<template>
  <div>
    <!-- 表单 -->
    <FormPanel ref="form" :labelWidth="100" :cols="4" :list="list" :isSubmitBtn="false" @formChange="formChange"></FormPanel>
    <ButtonArea :containerStyle="{ paddingLeft: '80px' }">
      <el-button size="small" type="primary" icon="el-icon-plus" :disabled="newBtnDisabled" @click="newBtnClick">新建</el-button>
      <UploadFile
        style="margin: 0 10px;"
        v-if="this.orderType != 80881009"
        :initial-value="fileInitalValue"
        isOnlyButton
        :limit="20"
        :disabled="addBtnDisabled && dcmbBtnDisabled"
        type="primary"
        icon="el-icon-download"
        :actionUrl="`${server.DMSCLOUD_PART}/basedata/ttSalesPart/importBuyPart`"
        @change="handleUploadChange"
        >导入</UploadFile
      >
      <UploadFile
        style="margin: 0 10px;"
        v-if="this.orderType == '80881009'"
        :initial-value="fileInitalValue"
        isOnlyButton
        :limit="20"
        :disabled="(addBtnDisabled && dcmbBtnDisabled) || this.isCheck == '1' || this.isCheck == '2'"
        type="primary"
        icon="el-icon-download"
        :actionUrl="`${server.DMSCLOUD_PART}/basedata/ttSalesPart/importBuyPartStock`"
        @change="handleUploadChange"
        >导入</UploadFile
      >
      <el-button size="small" type="primary" :disabled="addBtnDisabled && dcmbBtnDisabled && (this.isCheck == '1' || this.isCheck == '2')" :loading="exportModelLoading" @click="exportModel"
        >导出模板</el-button
      >
      <AjaxButton size="small" type="primary" icon="el-icon-folder" :disabled="saveBtnDisabled || this.isCheck == '1' || this.isCheck == '2'" :click="saveBtnClick">保存</AjaxButton>
      <AjaxButton
        size="small"
        type="primary"
        icon="el-icon-folder"
        :disabled="saveBtnDisabled || this.isCheck == '1' || this.isCheck == '2'"
        :click="saveBtnClick.bind(this, 1)"
        v-if="this.orderType == '80881009'"
        >提交</AjaxButton
      >
      <el-button size="small" type="primary" icon="el-icon-folder" :disabled="bookedBtnDisabled || (this.isCheck != null && this.isCheck != '2')" @click="bookedBtnClick">入库</el-button>
      <el-button size="small" type="primary" icon="el-icon-refresh-left" :disabled="cancelBtnDisabled" @click="cancelBtnClick">取消</el-button>
      <el-button size="small" type="primary" icon="el-icon-printer" :disabled="prindfBtnDisabled" @click="handleDayin">打印</el-button>
      <el-button size="small" type="primary" :loading="assignLeisureLoading" :disabled="saveBtnDisabled" @click="handleAssignLeisurePosition">默认空库位</el-button>
      <el-button size="small" type="primary" :disabled="deleteWholeList" @click="deleteWholeListClick">删除整单</el-button>
    </ButtonArea>
    <!-- 表格 -->
    <FilterTable
      ref="table"
      :columns="columns"
      columnsRef="partPartInventoryPartInventoryIndex"
      :isServerColumnsRef="false"
      :dataSource="dataSource"
      :isMemoryPagination="true"
      :onRowSelectChange="handleTableRowSelectChange"
      :onCellChange="onCellChange"
      :onSyncTableData="onTableDataChange"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <!-- :onSyncTableData="val => (dataSource = val)" -->
      <!--      <template slot="moreActions">-->
      <!--        <span v-if="showDeleteBtn" @click="deleteBtnClick">删除数据</span>-->
      <!--      </template>-->
      <template slot="controls">
        <el-button size="small" type="primary" :disabled="addBtnDisabled" @click="showAddPanel">新增</el-button>
        <!-- <el-button size="mini" type="primary" @click="qianliaotest">欠料</el-button> -->
        <!-- <el-button size="mini" type="primary" :disabled="dcmbBtnDisabled" icon="el-icon-download">模板导出</el-button>
        <el-button size="mini" type="primary" :disabled="drBtnDisabled" icon="el-icon-upload2">导入</el-button>-->
        <!-- <el-button size="mini" type="primary" :disabled="dcBtnDisabled" icon="el-icon-download">导出</el-button> -->
        <!-- <el-button size="small" type="primary" :disabled="returnBtnDisabled" @click="showReturnPanel">退货</el-button> -->
        <!-- <el-button size="mini" type @click="showFahuodan" :disabled="fahuodanDisabled">发货单</el-button>
        <el-button size="mini" type @click="showCaigou" :disabled="caigouDisabled">采购订单</el-button>
        <el-button size="mini" type @click="showJiaoyipingtai" :disabled="jiaoyipingtaiDisabled">交易平台</el-button>
        <el-button size="mini" type @click="showWenhua" :disabled="wenhuaDisabled">文化公司</el-button>-->
        <el-button size="small" type="primary" :disabled="showDeleteBtn" @click="deleteBtnClick">删除数据</el-button>
      </template>
    </FilterTable>
    <!-- 打印 -->
    <div v-if="dy">
      <BasePrint ref="Salesprint" :data="SalesprintList" template="templatepartInventory" />
    </div>
    <!-- 模态框 -->
    <div>
      <!-- 查询客户 -->
      <BaseDialog title="业务往来客户选择" :visible.sync="isShowSearchCustomer" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
        <SearchCustomer :customerNo="kehuxuanze" @close="isShowSearchCustomer = false" @addCustomerCode="confirmSearchCustomer" />
      </BaseDialog>
      <!-- 查询订单-->
      <BaseDialog title="入库单号" :visible.sync="isShowSearchOrder" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
        <SearchOrder :ptype="ptype" :stockInNo="rukudanhao" @confirm="confirmSearchOrder" @cancel="isShowSearchOrder = false" />
      </BaseDialog>
      <!-- 新增 -->
      <BaseDialog width="80%" title="采购入库新增" :visible.sync="isShowAddPanel" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
        <AddPanel @confirm="confirmAddPanel" @cancel="isShowAddPanel = false" />
      </BaseDialog>
      <!-- 退货 -->
      <BaseDialog title="采购退货" :visible.sync="isShowReturnPanel" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
        <PartReturn :customerCode="customerCode" @confirm="confirmReturnPanel" @cancel="isShowReturnPanel = false" />
      </BaseDialog>
      <!-- 退货编辑 -->
      <BaseDialog title="采购退货编辑" :visible.sync="isShowReturnEditPanel" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
        <PartReturnEdit :formData="partReturnEditFormData" @confirm="confirmReturnEditPanel" @cancel="isShowReturnEditPanel = false" />
      </BaseDialog>
      <!-- 编辑 -->
      <BaseDialog title="采购入库编辑" :visible.sync="isShowEditPanel" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
        <EditPanel :selectRow="selectRowEdit" @confirm="confirmEditPanel" @cancel="isShowEditPanel = false" />
      </BaseDialog>
      <!-- 保存提示 -->
      <BaseDialog title="入库" :visible.sync="isShowBookedTipPanel" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
        <BookedTip :tableData="dataSource" @confirm="confirmBookedTipPanel" @cancel="isShowBookedTipPanel = false" />
      </BaseDialog>
      <!-- 发货单 -->
      <BaseDialog title="货运单号" :visible.sync="isShowfahuodan" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
        <Fahuodan :orderType="orderType" :orderNo="orderNo" @confirm="confirmFahuodan" @cancel="isShowfahuodan = false" />
      </BaseDialog>
      <!-- 采购订单 -->
      <BaseDialog title="采购订单" :visible.sync="isShowcaigou" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
        <Caigou :orderNo="orderNo" :orderType="orderType" @confirm="confirmCaigou" @cancel="isShowcaigou = false" />
      </BaseDialog>
      <!-- 交易平台 -->
      <BaseDialog title="交易平台单号选择" :visible.sync="isShowjiaoyipingtai" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
        <Jiaoyipingtai :orderNo="orderNo" :orderType="orderType" @confirm="confirmJiaoyipingtai" @cancel="isShowjiaoyipingtai = false" />
      </BaseDialog>
      <!-- 文化公司 -->
      <BaseDialog title="文化公司" :visible.sync="isShowwenhua" destroyOnClose>
        <Wenhua :orderNo="orderNo" :orderType="orderType" @confirm="confirmWenhua" @cancel="isShowwenhua = false" />
      </BaseDialog>
      <!-- 编辑发货单 -->
      <BaseDialog title="编辑发货单" :visible.sync="EditFahuodan" destroyOnClose>
        <EditFahuodan :selectRow="selectRowEdit" @confirm="confirmEditFahuodan" @cancel="EditFahuodan = false" />
      </BaseDialog>
      <!-- 编辑采购 -->
      <BaseDialog title="编辑采购" :visible.sync="EditCaigou" destroyOnClose>
        <EditCaigou :selectRow="selectRowEdit" @confirm="confirmEditCaigou" @cancel="EditCaigou = false" />
      </BaseDialog>
      <!-- 编辑交易平台 -->
      <BaseDialog title="编辑交易平台" :visible.sync="EditJiaoyipingtai" destroyOnClose>
        <EditJiaoyipingtai :selectRow="selectRowEdit" @confirm="confirmEditJiaoyipingtai" @cancel="EditJiaoyipingtai = false" />
      </BaseDialog>
      <!-- 编辑文化 -->
      <BaseDialog title="编辑文化" :visible.sync="EditWenhua" destroyOnClose>
        <EditWenhua :selectRow="selectRowEdit" @confirm="confirmEditWenhua" @cancel="EditWenhua = false" />
      </BaseDialog>

      <!-- 欠料单配件 -->
      <BaseDialog title="欠料单提醒" :visible.sync="inDebtVisible" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
        <inDebtPart :stockInNo="inDebtstockInNo" @close="inDebtVisible = false" />
      </BaseDialog>

      <!-- 库位选择弹窗 -->
      <BaseDialog title="选择库位" width="30%" :visible.sync="positionListVisible" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
        <positionSelect :positionList="positionDialogList" :editRow="positionEditRow" @onConfirm="handlePositionSelectConfirm" @close="positionListVisible = false" />
      </BaseDialog>

      <!-- 签收弹窗 -->
      <BaseDialog title="签收" :visible.sync="signVisible" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
        <editPartOrderSign :id="fahuodanData.id || ''" :billNo="fahuodanData.vbeln || ''" @close="handleSignDialogClose" />
      </BaseDialog>
      <!-- 同步配件弹窗 -->
      <BaseDialog
        :visible.sync="isShowTongBu"
        title="以下配件入库价格与主文件采购价格不一致，请同步主文件"
        destroyOnClose
        :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
      >
        <JiaGeTiShi :dataIn="jiaGeTiShiData" @confirm="confirmTongBu" @cancel="isShowTongBu = false"></JiaGeTiShi>
      </BaseDialog>
    </div>
  </div>
</template>

<script>
import { state, mutations } from './store';
import SERVER from '@/api/server';
import { dictionary } from '@/utils/dictMixin';
import { confirmAction, notifyAction, isFormEmpty } from '@/utils';
import * as Util from '@/utils/index.js';
import _ from 'lodash';
import SearchOrder from './components/SearchOrder';
import SearchCustomer from './components/searchCustomerPage';
import { exportBuyModel } from '@/api/part/partOut/partSales/index';
import AddPanel from './components/AddPanel';
import EditPanel from './components/EditPanel';
import BookedTip from './components/BookedTip';
import PartReturn from './components/PartReturn';
import { arrayObjDeWeight } from '@/utils/index';
import PartReturnEdit from './components/PartReturnEdit';
import inDebtPart from './components/inDebtPart';
import editPartOrderSign from '@/pages/part/partInventory/partSign/editPartOrderSign';

import {
  deleteWholeListClickMethod,
  partbuySave,
  partbuyStockInItem,
  partbuyQueryCanReturnNum,
  partbuyEnterRecord,
  partgetfourData,
  queryThreeTypeOrderDetail,
  queryUsableLocations,
  getDealerUser,
  stockIn,
  printData,
  queryInventoryPartIsRelevanceInDebt,
  queryUseablePositionListByStorage,
  queryParyHasStorageById
} from '@/api/part/partInventory/partInventory/index.js';
// 增加获取系统参数引用
import { getStorageList, querySysParam } from '@/api/part/common';
import { getCustomerList, getCustomerData } from '@/api/part/partInventory/adjustInventory/index';
import { getPartInfo, updatePartInfoByPartNos, queryUnitCode } from '@/api/part/partInfo';
import { queryTex, queryPartinventoryPrintParam } from '@/api/part/common';
import { getAppId } from '@/assets/js/auth';

import moment from 'moment';
import Fahuodan from './components/fahuodan';
import Caigou from './components/caigou';
import Jiaoyipingtai from './components/jiaoyipingtai';
import Wenhua from './components/wenhua';
import EditWenhua from './components/EditWenhua';
import EditCaigou from './components/EditCaigou';
import EditFahuodan from './components/EditFahuodan';
import EditJiaoyipingtai from './components/EditJiaoyipingtai';
import positionSelect from './components/positionSelect';
import JiaGeTiShi from './components/JiaGeTiShi';
import { dealerPrintApi } from '@/api/repair/index.js';
import transverseIndexVue from '../../report/revenueAndExpenditure/transverseIndex.vue';

const types = {
  stockInNo: 'stockInNo', // 入库单号
  customerCode: 'customerCode1', // 供销商代码
  priceAddRate: 'priceAddRate', // 加价率
  tax: 'tax', // 税率
  stockInType: 'stockInType', // 入库类型
  sheetCreateDate: 'sheetCreateDate', // 开单日期
  remark: 'remark', // 备注
  // settle: 'orderNo' // 订单号选择  （发货单、采购订单、交易平台、文化公司）
  settle: 'purchaseCode' // 订单号选择  （发货单、采购订单、交易平台、文化公司）
};
const pageStateTypes = {
  none: 'none', // 页面初始化
  new: 'new', // 新建按钮
  add: 'add', // 新增
  return: 'return', // 退货
  add_edit: 'add_edit', // 新增 编辑
  return_edit: 'return_edit', // 退货编辑

  fahuodan: 'fahuodan', // 发货单
  caigou: 'caigou', // 采购订单
  jiaoyipingtai: 'jiaoyipingtai', // 交易平台
  wenhua: 'wenhua', // 文化公司,
  kucun: 'kucun' // 库存导入
};

export default {
  name: 'cgrk',
  components: {
    SearchOrder,
    AddPanel,
    EditPanel,
    PartReturn,
    BookedTip,
    SearchCustomer,
    PartReturnEdit,
    Fahuodan,
    Caigou,
    Jiaoyipingtai,
    Wenhua,
    EditWenhua,
    EditCaigou,
    EditFahuodan,
    EditJiaoyipingtai,
    inDebtPart,
    positionSelect,
    JiaGeTiShi,
    editPartOrderSign // 签收页面
  },
  mixins: [dictionary],
  data() {
    return {
      flagPd: false,
      flagTB: false, // 是否提示同步采购价
      printdataList: [], // 打印数据
      fileInitalValue: [],
      cunPrintid: '',
      cunTax: 0.13,
      tax: 0.13,
      dyListTop: [], // 打印数据
      cunUserList: [],
      dyList: [], // 打印数据
      dy: false,
      shanchu: [],
      orderNo: '',
      orderType: '',
      list: this.createList(),
      columns: this.createColumns(),
      dataSource: [],
      deleteRows: [],
      editRow: {},
      pageState: pageStateTypes.none,
      partReturnEditFormData: {},
      inDebtstockInNo: '',
      selectedTableRowData: [], // 选中的table数据
      // 打印的数据
      SalesprintList: {}, // 打印销售单
      /** */
      customerName: '',
      /** 模态框 状态 */
      isShowSearchOrder: false, // 入库单号
      isShowAddPanel: false, // 新增
      isShowEditPanel: false,
      selectRowEdit: {},
      isShowReturnPanel: false,
      isShowReturnEditPanel: false,
      isShowSearchCustomer: false, // 客户选择
      isShowPartReturn: false, // 入库
      isShowGoodsOrder: false, // 货运单选择
      isShowBookedTipPanel: false, // 入账提示
      isShowfahuodan: false, // 发货单
      isShowcaigou: false, // 采购订单
      isShowjiaoyipingtai: false, // 交易平台
      isShowwenhua: false, // 文化公司
      EditFahuodan: false, // 编辑发货单
      EditCaigou: false, // 编辑采购
      EditJiaoyipingtai: false, // 编辑交易平台
      EditWenhua: false, // 编辑文化
      inDebtVisible: false, // 是否显示欠料单据想你想
      isShowTongBu: false, // 同步提示
      isFinished: false,
      /** 按钮状态 */
      // 表格里
      addBtnDisabled: false, // 新增按钮
      returnBtnDisabled: false, // 退货按钮
      fahuodanDisabled: false, // 发货单按钮
      caigouDisabled: false, // 采购订单按钮
      jiaoyipingtaiDisabled: false, // 交易平台按钮
      wenhuaDisabled: false, // 文化公司按钮

      dcmbBtnDisabled: true, // 导出模板
      drBtnDisabled: false, // 导入
      dcBtnDisabled: false, // 导出
      // 下面
      newBtnDisabled: false, // 新建
      saveBtnDisabled: false, // 保存
      bookedBtnDisabled: false, // 入账
      cancelBtnDisabled: false, // 取消
      deleteWholeList: false, // 删除整单
      showDeleteBtn: false, // 删除数据
      prindfBtnDisabled: false, // 打印
      // 控制操作按钮
      operateBtnDisabled: null,
      defaultDealerCodeName: { code: 'FAW-VW', name: '一汽大众汽车有限公司' },
      positionListVisible: false, // 是否显示库位选择弹框
      storageDic: [], // 仓库字典
      storagePositionList: {
        // table仓库库位篮子
        // sotrageCode: [posCode1, posCode1]
      },
      positionEditRow: {}, // 正在选择库位的行项数据
      positionDialogList: [], // 弹窗选择库位的库位
      assignLeisureLoading: false, // 赋值空库位按钮loading状态
      hideoperation: true, // 是否隐藏操作table列
      printParams: {}, // 打印参数
      exportModelLoading: false,
      precision: 4, // 保留精度
      fahuodanData: {}, // 发货单数据
      jiaGeTiShiData: [], // 价格提示数据
      signVisible: false, // 是否显示签收弹窗
      ckDataList: [], // 仓库数据
      CKFlag: 'flag', // 采购表示
      server: SERVER,
      isCheck: null
    };
  },
  computed: {
    customerCode() {
      return this.list.find(x => x.fieldName === types.customerCode).initialValue;
    },
    kehuxuanze() {
      return this.list.find(x => x.fieldName === types.customerCode).initialValue;
    },
    rukudanhao() {
      return this.list.find(x => x.fieldName === types.stockInNo).initialValue;
    },
    // 入库单据类型
    inOrderType() {
      return this.list.find(x => x.fieldName == types.stockInType).initialValue;
    },
    ptype() {
      return this.$route.meta.ptype || '';
    }
  },
  watch: {
    dataSource: {
      handler(newVal) {
        console.log(newVal);
        if (!isFormEmpty(this.CKFlag)) {
          this.computedTableData(newVal);
        }
      },
      deep: true
    },
    inOrderType(newVal) {
      if (newVal) {
        this.quertStorageListByIncountType(newVal);
      }
    }
  },
  mounted() {
    window.cgrk_page = this;
    // this.querySysTex();
    this.setPageState(pageStateTypes.none);
    this.queryUnitCode();
    this.quertStorageListByIncountType();
    // this.initDictData();
    this.getDealerUser();
    // this.queryPrintParams(); // 查询打印参数
    // this.queryAutoPrintParams(); // 查询自动打印参数
  },
  methods: {
    // 查询自动打印参数
    async queryAutoPrintParams() {
      let res = await querySysParam(this.ptype ? this.ptype : 'SPA', 'DYRKD');
      if (res.data && res.data.length) {
        let result = 'true';
        if (!res.data[0].bParaValue) {
          result = res.data[0].defaultValue == '1' ? 'false' : 'true';
        }
        if (res.data[0].bParaValue == '1') {
          result = 'false';
        } else {
          result = 'true';
        }
        this.list.find(item => item.fieldName == 'autoPrint').initialValue = result;
      }
    },
    // 获取表单id的方法
    async stockIn(val) {
      const res = await stockIn({ stockInNo: val });
      this.cunPrintid = res.data.rows[0].PART_BUY_ID;
      console.log(this.cunPrintid, 'this.cunPrintid');
    },
    // 获取税率
    async querySysTex() {
      let res = await queryTex();
      this.tax = res.data || res.data == 0 ? res.data : 0.13;
      this.cunTax = res.data || res.data == 0 ? res.data : 0.13;
      this.list.find(item => item.fieldName == 'tax').initialValue = res.data || res.data == 0 ? res.data : 0.13;
    },
    // 单位下拉框
    async queryUnitCode() {
      const res3 = await queryUnitCode();
      if (res3.resultCode == 200) {
        let data = arrayObjDeWeight(res3.data, 'UNIT_CODE');
        // this.columns.find(item => item.dataIndex == 'UNIT').editItems = res3.data.map(x => ({ text: x.UNIT_NAME, value: x.UNIT_CODE }));
        this.columns.find(item => item.dataIndex == 'UNIT_CODE').filterItems = data.map(x => ({ text: x.UNIT_NAME, value: x.UNIT_CODE }));
        this.columns.find(item => item.dataIndex == 'UNIT_CODE').dictItems = data.map(x => ({ text: x.UNIT_NAME, value: x.UNIT_CODE }));
      }
    },
    async getDealerUser() {
      const res = await getDealerUser();
      this.cunUserList = res.data;
    },
    getFormListValue(fieldName) {
      return this.list.find(x => x.fieldName === fieldName).initialValue;
    },
    createList() {
      return [
        {
          type: 'INPUT',
          label: '入库单号',
          fieldName: types.stockInNo,
          unitRender: () => {
            return (
              <el-button
                icon="el-icon-search"
                onClick={() => {
                  this.isShowSearchOrder = true;
                }}
              ></el-button>
            );
          },
          onEnter: val => {
            console.log('采入库单号 onEnter');
            this.isShowSearchOrder = true;
          }
        },
        {
          type: 'INPUT',
          label: '业务往来客户代码',
          fieldName: types.customerCode,
          hidden: true,
          rules: [{ required: true, message: '      ', trigger: 'change' }],
          unitRender: p => {
            return (
              <div>
                <el-button
                  icon="el-icon-search"
                  onClick={() => {
                    this.isShowSearchCustomer = true;
                  }}
                ></el-button>
              </div>
            );
          },
          onEnter: val => {
            console.log('业务往来客户 onEnter', val);
            this.isShowSearchCustomer = true;
            // this.gdClickHandle();
          }
        },
        {
          type: 'INPUT',
          label: '业务往来客户',
          fieldName: 'name',
          itemList: [],
          rules: [{ required: true, message: '      ', trigger: 'change' }],
          unitRender: p => {
            return (
              <div>
                <el-button
                  icon="el-icon-search"
                  onClick={() => {
                    this.isShowSearchCustomer = true;
                  }}
                ></el-button>
              </div>
            );
          },
          onEnter: val => {
            console.log('业务往来客户 onEnter', val);
            this.isShowSearchCustomer = true;
            // this.gdClickHandle();
          }
        },
        // {
        //   type: 'INPUT',
        //   label: '加价率',
        //   fieldName: types.priceAddRate,
        //   disabled: true
        // },
        // {
        //   type: 'SELECT',
        //   label: '默认仓库',
        //   fieldName: 'defaultStorage',
        //   disabled: false,
        //   itemList: [],
        //   change: e => {
        //     console.log(e);
        //   }
        // },
        {
          type: 'SELECT',
          label: '入库类型',
          fieldName: types.stockInType,
          placeholder: '请选择...',
          rules: [{ required: true, message: '      ', trigger: 'change' }],
          itemList: this.createDictList(8088),
          // itemList:[],
          change: value => {
            console.log('入库类型 change', value);
            this.orderNo = '';
            this.shanchu = [];
            this.list.find(x => x.fieldName === types.settle).initialValue = '';
            this.list.find(x => x.fieldName === types.stockInType).initialValue = '';
            this.saveBtnDisabled = true;
            if (value == 80881001) {
              this.setPageState(pageStateTypes.add);
              this.list.find(x => x.fieldName == 'tax').disabled = false;
            } else if (value == 80881002) {
              this.setPageState(pageStateTypes.return);
            } else if (value == 80881003) {
              console.log('发货单');
              // this.setDefaultDealerToVw();
              this.orderType = 80881003;
              this.list.find(x => x.fieldName == 'tax').initialValue = 0.13;
              this.list.find(x => x.fieldName == 'tax').disabled = true;
              this.setPageState(pageStateTypes.fahuodan);
            } else if (value == 80881004) {
              console.log('采购订单');
              this.orderType = 80881004;
              this.setPageState(pageStateTypes.caigou);
            } else if (value == 80881005) {
              console.log('交易平台');
              // this.setDefaultDealerToVw();
              this.orderType = 80881005;
              this.setPageState(pageStateTypes.jiaoyipingtai);
            } else if (value == 80881006) {
              console.log('文化公司');
              this.orderType = 80881006;
              this.setPageState(pageStateTypes.wenhua);
            } else if (value == 80881009) {
              console.log('库存导入');
              this.orderType = 80881009;
              this.setPageState(pageStateTypes.kucun);
            }
          }
        },
        {
          type: 'INPUT',
          label: '货运单号',
          fieldName: types.settle, // 还没给参数
          disabled: true,
          unitRender: p => {
            return (
              <div>
                <el-button
                  icon="el-icon-search"
                  onClick={() => {
                    if (!this.fahuodanDisabled) {
                      // this.partgetfourData()
                      this.isShowfahuodan = true; // 发货单
                    } else if (!this.caigouDisabled) {
                      this.isShowcaigou = true; // 采购订单
                    } else if (!this.jiaoyipingtaiDisabled) {
                      this.isShowjiaoyipingtai = true; // 交易平台
                    } else if (!this.wenhuaDisabled) {
                      // this.isShowwenhua = true //文化公司
                      this.$notify({
                        title: '提示',
                        message: '暂无该功能',
                        type: 'warning'
                      });
                    }
                  }}
                ></el-button>
              </div>
            );
          },
          onEnter: val => {
            console.log('单号选择 onEnter', val);
            if (!this.fahuodanDisabled) {
              // this.partgetfourData()
              this.isShowfahuodan = true; // 发货单
            } else if (!this.caigouDisabled) {
              this.isShowcaigou = true; // 采购订单
            } else if (!this.jiaoyipingtaiDisabled) {
              this.isShowjiaoyipingtai = true; // 交易平台
            } else if (!this.wenhuaDisabled) {
              // this.isShowwenhua = true //文化公司
              this.$notify({
                title: '提示',
                message: '暂无该功能',
                type: 'warning'
              });
            }
          }
        },
        // {
        //   type: 'INPUT',
        //   label: '货运单号',
        //   fieldName: 'delvieryNo',
        //   unitRender: () => {
        //     return <el-button icon="el-icon-search" onClick={() => {}}></el-button>;
        //   },
        //   onEnter: val => {
        //     console.log('货运单号 onEnter');
        //     // this.gdClickHandle();
        //   }
        // },
        {
          type: 'INPUT',
          label: '开单日期',
          fieldName: types.sheetCreateDate,
          disabled: true
        },
        {
          type: 'INPUT',
          label: '备注',
          fieldName: types.remark,
          change: val => {
            if (this.dataSource.length > 0) {
              this.newBtnDisabled = true; // 新建
              this.saveBtnDisabled = false; // 保存
              this.bookedBtnDisabled = true; // 入账
              this.cancelBtnDisabled = false; // 取消
              this.deleteWholeList = false; // 删除整单
              this.showDeleteBtn = false; // 删除数据
              this.prindfBtnDisabled = true; // 打印
            }
          }
        },
        // {
        //   type: 'CHECKBOX',
        //   label: '是否打印',
        //   fieldName: 'autoPrint',
        //   initialValue: 'true',
        //   options: {
        //     trueValue: 'true',
        //     falseValue: 'false'
        //   }
        // },
        // {
        //   type: 'INPUT',
        //   label: '默认库区',
        //   fieldName: 'areaCode',
        //   disabled: false,
        //   change: val => {
        //     this.handleAreaCodeChange(val);
        //     console.log(val, '库区变化');
        //   }
        // },
        {
          type: 'INPUT_NUMBER', // INPUT_NUMBER
          label: '税率',
          disabled: true,
          fieldName: 'tax',
          disabled: true,
          initialValue: 0.13,
          max: 1,
          min: 0.0,
          change: val => {
            let data = val;
            console.log(val, '税率变化');
            if (data <= 1 && data >= 0) {
            } else {
              data = this.cunTax;
            }
            let dataVal = Number(data).toFixed(2);
            mutations.setTax(dataVal);
            this.tax = dataVal;
            console.log(dataVal, 'dataVal');
            this.handleTax(dataVal);
            if (this.dataSource.length > 0) {
              this.newBtnDisabled = true; // 新建
              this.saveBtnDisabled = false; // 保存
              this.bookedBtnDisabled = true; // 入账
              this.cancelBtnDisabled = false; // 取消
              this.deleteWholeList = false; // 删除整单
              this.showDeleteBtn = false; // 删除数据
              this.prindfBtnDisabled = true; // 打印
            }
          }
        }
      ];
    },
    // 配件导入成功事件
    handleUploadChange(e) {
      console.log('e:::', e);
      if (e != 1) {
        // if (this.initReceiver) {
        // console.log('导入文件上传成功', e[e.length - 1].url);
        this.fileInitalValue = e;
        let excelData = _.cloneDeep(e[e.length - 1].url.result);
        // for (const item of this.tableData) {
        //   for (const items of excelData) {
        //     if (item.PART_NO == items.PART_NO && item.STORAGE_CODE == items.STORAGE_CODE) {
        //       item.PART_QUANTITY = Number(item.PART_QUANTITY) + Number(items.PART_QUANTITY);
        //     }
        //   }
        //   excelData = excelData.filter(items => {
        //     return items.PART_NO != item.PART_NO || item.STORAGE_CODE != items.STORAGE_CODE;
        //   });
        // }
        console.log(excelData, 'excelData');
        if (excelData.length) {
          this.formatPartsData(excelData);
        }
        this.handleDetailSelectConfirm(excelData, e[e.length - 1].url.errorList);
        // } else {
        //   this.$notify.error({ title: '提示信息', message: `请选择领料人` });
        // }
      }
    },
    formatPartsData(list) {
      list.map((item, index) => {
        // 处理采购数量，套餐类型单独处理 incount数量x订购套数
        this.$set(list[index], 'IN_QUANTITY', item.PART_QUANTITY);
        this.$set(list[index], 'IN_PRICE', item.PART_COST_PRICE / (1 + this.tax));
        this.$set(list[index], 'IN_AMOUNT', item.PART_COST_PRICE * item.PART_QUANTITY);
        this.$set(list[index], 'IN_PRICE_TAXED', item.PART_COST_PRICE);
        this.$set(list[index], 'IN_AMOUNT_TAXED', item.IN_PRICE_TAXED * item.PART_QUANTITY);
      });
    },
    handleDetailSelectConfirm(e, data) {
      let partList = e;
      // 校验重复配件
      let newPartArr = [],
        repeatingPartArr = []; // 重复配件，新配件
      console.log('datasource::', this.dataSource);
      console.log('partList::', partList);
      partList.map(item => {
        if (this.dataSource.find(x => x.partNo == item.partNo)) {
          repeatingPartArr.push(item);
        } else {
          newPartArr.push(item);
        }
      });
      if (repeatingPartArr.length) {
        let idsArr = repeatingPartArr.map(item => item.PART_NO);
        notifyAction('此订单类型禁止添加重复配件，配件代码：' + idsArr.join(','), 'warning');
      }
      newPartArr = JSON.parse(JSON.stringify(newPartArr)); // 浅拷贝防止原始数据修改
      this.formatPartsData(newPartArr);
      this.$refs.table.$refs.pageTable.EXECUTE_INSERT(newPartArr);
      if (data.length > 0) {
        let errorData = data.map(x => {
          if (x.result == '查询不到仓库') {
            return '仓库：' + x.storageCode + '不存在';
          } else {
            return '配件' + x.partNo + '不存在';
          }
        });
        this.$notify.warning({ title: '提示信息', message: `导入成功，已做去重处理，${errorData.join('，')}，请确认模板` });
      } else {
        notifyAction('配件导入成功，已做去重处理', 'success');
      }
      this.saveBtnDisabled = false;
      // if (this.orderType == 80881009) {
      //   console.log('除非');
      //   this.columns.find(x => x.dataIndex == 'IN_PRICE_TAXED').disabled = true;
      // }
    },
    exportModel() {
      this.exportModelLoading = true;
      exportBuyModel().then(res => {
        console.log('res:::', res);
        Util.exportExcelFile(res.data, '采购入库模板');
        this.exportModelLoading = false;
      });
    },
    createColumns() {
      return [
        {
          title: '序号',
          // sorter: true,
          width: 70,
          dataIndex: 'xuhao',
          sorter: true,
          render: props => {
            return <span>{props.row.$index + 1}</span>;
          },
          sorter: true
        },
        {
          title: '操作',
          // sorter: true,
          dataIndex: 'column-action',
          minWidth: 100,
          render: props => {
            // <el-button onClick={() => this.deleteBtnClick(props)} type="text" disabled={this.operateBtnDisabled} size="mini">
            //   删除
            // </el-button>
            // <el-divider direction="vertical" />
            return (
              <div>
                <el-button onClick={() => this.tableCellEditClick(props)} type="text" disabled={this.operateBtnDisabled || this.hideoperation || this.isFinished} size="mini">
                  编辑
                </el-button>
              </div>
            );
          }
        },
        {
          title: '仓库',
          sorter: true,
          minWidth: 150,
          dataIndex: 'STORAGE_CODE',
          //= disabled: false,
          // editable: true,
          // defaultEditable: true,
          // editType: 'select',
          // editItems: this.storageDic,
          filter: false,
          filterType: 'checkbox',
          filterItems: this.storageDic,
          render: params => {
            let storage = params.row.STORAGE_CODE;
            let positionCode = params.row.STORAGE_POSITION_CODE;
            return (
              <el-select
                value={params.row.STORAGE_CODE}
                // || !Util.isAuthorized('1313', '13131013')
                disabled={this.getFormListValue(types.stockInType) == '80881003' || this.isFinished || this.getFormListValue(types.stockInType) == '80881009'}
                placeholder="请选择..."
                onChange={val => {
                  // 当仓库改变时将现有库位增加到该仓库库位篮子中
                  if (this.storagePositionList[storage] && positionCode && !this.storagePositionList[storage].includes(positionCode)) {
                    this.storagePositionList[storage].unshift(positionCode);
                  }
                  this.bookedBtnDisabled = true;
                  params.row.STORAGE_CODE = val;
                  params.row.STORAGE_POSITION_CODE = '';
                  params.row.STORAGE_TYPE = this.ckDataList.find(item => item.STORAGE_CODE == val).STORAGE_TYPE;
                }}
              >
                {this.storageDic.map((item, index) => (
                  <el-option key={index} label={item.text} value={item.value}></el-option>
                ))}
              </el-select>
            );
          }
        },
        {
          title: '仓库类型',
          sorter: true,
          width: 150,
          dataIndex: 'STORAGE_TYPE',
          filter: false,
          filterItems: this.createDictList(5000),
          dictItems: this.createDictList(5000),
          filterType: 'checkbox'
        },
        {
          title: '库位',
          sorter: true,
          width: 150,
          dataIndex: 'STORAGE_POSITION_CODE',
          filter: false,
          filterType: 'input',
          // disabled={!!params.row.ITEM_ID && params.row.ITEM_ID != 'N'}
          render: params => {
            return (
              <el-input
                placeholder="请选择..."
                disabled={
                  (this.getFormListValue(types.stockInType) == '80881003' && !_.isNil(this.getFormListValue(types.stockInNo)) && this.getFormListValue(types.stockInNo).length > 0) ||
                  this.isFinished ||
                  this.isCheck == '1' ||
                  this.isCheck == '2'
                }
                onChange={val => {
                  this.bookedBtnDisabled = true;
                }}
                value={params.row.STORAGE_POSITION_CODE}
                readonly
                size="mini"
              >
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  onClick={() => {
                    this.handleChosePosition(params.row);
                  }}
                ></el-button>
              </el-input>
            );
          }
        },
        {
          title: '配件代码',
          width: 180,
          sorter: true,
          dataIndex: 'PART_NO',
          showOverflowTooltip: true,
          filter: false,
          filterType: 'input'
        },
        {
          title: '配件名称',
          width: 180,
          sorter: true,
          dataIndex: 'PART_NAME',
          showOverflowTooltip: true,
          filter: false,
          filterType: 'input'
        },
        {
          title: '计量单位',
          sorter: true,
          dataIndex: 'UNIT_CODE',
          // disabled: true,
          // editable: true,
          // editType: 'select',
          // editItems: [],
          filter: false,
          filterType: 'checkbox',
          filterItems: [],
          dictItems: []
        },
        {
          title: '入库数量',
          sorter: true,
          dataIndex: 'IN_QUANTITY',
          precision: 2,
          filter: false,
          summation: true,
          filterType: 'number',
          min: 0,
          max: Infinity,
          widht: 130,
          // editable: true,
          // defaultEditable: true,
          // editType: 'number',
          render: params => {
            return (
              <el-input-number
                type="number"
                min={0}
                disabled={
                  (this.getFormListValue(types.stockInType) == '80881003' && !_.isNil(this.getFormListValue(types.stockInNo)) && this.getFormListValue(types.stockInNo).length > 0) ||
                  this.isFinished ||
                  this.isCheck == '1' ||
                  this.isCheck == '2'
                }
                value={params.row.IN_QUANTITY}
                size="small"
                style="width: 100px"
                precision={2}
                controls={false}
                onChange={e => {
                  this.CKFlag = 'flag';
                  this.bookedBtnDisabled = true;
                  console.log(e, 'e::::');
                  if (_.isNil(e)) {
                    params.row.IN_QUANTITY = '';
                    params.row.IN_QUANTITY = 0;
                  } else {
                    params.row.IN_QUANTITY = e;
                  }
                }}
              ></el-input-number>
            );
          }
        },
        // {
        //   title: '签收数量',
        //   sorter: true,
        //   dataIndex: 'SIGN_QUANTITY',
        //   precision: 2,
        //   filter: false,
        //   filterType: 'number',
        //   min: 0,
        //   max: Infinity,
        //   widht: 130
        // },
        // {
        //   title: '不含税单价',
        //   sorter: true,
        //   dataIndex: 'IN_PRICE',
        //   summation: true,
        //   filter: false,
        //   filterType: 'number',
        //   precision: 4,
        //   render: params => {
        //     return (
        //       <el-input-number
        //         type="number"
        //         disabled={!!params.row.ITEM_ID && params.row.ITEM_ID != 'N'}
        //         value={params.row.IN_PRICE}
        //         size="small"
        //         style="width: 100px"
        //         precision={4}
        //         controls={false}
        //         onChange={e => {
        //           this.CKFlag = 'flag';
        //           params.row.IN_PRICE = e;
        //           this.bookedBtnDisabled = true; // 保存后才能入库
        //         }}
        //       ></el-input-number>
        //     );
        //   }
        // },
        // {
        //   title: '不含税金额',
        //   sorter: true,
        //   dataIndex: 'IN_AMOUNT',
        //   precision: 2,
        //   summation: true,
        //   filter: false,
        //   filterType: 'number'
        // },
        {
          title: '含税单价',
          sorter: true,
          dataIndex: 'IN_PRICE_TAXED',
          precision: 2,
          filter: false,
          disabled: false,
          filterType: 'number',
          render: params => {
            return (
              <el-input-number
                type="number"
                disabled={
                  (this.getFormListValue(types.stockInType) == '80881003' && !_.isNil(this.getFormListValue(types.stockInNo)) && this.getFormListValue(types.stockInNo).length > 0) ||
                  this.isFinished ||
                  this.isCheck == '1' ||
                  this.isCheck == '2'
                }
                value={params.row.IN_PRICE_TAXED}
                size="small"
                min={0}
                style="width: 100px"
                precision={2}
                controls={false}
                onChange={e => {
                  this.bookedBtnDisabled = true;
                  this.CKFlag = 'flag';
                  params.row.IN_PRICE_TAXED = e || 0;
                  params.row.IN_PRICE = e || 0 / (Number(this.tax) + 1);
                }}
              ></el-input-number>
            );
          }
        },
        {
          title: '含税金额',
          sorter: true,
          dataIndex: 'IN_AMOUNT_TAXED',
          precision: 2,
          summation: true,
          filter: false,
          filterType: 'number'
        },
        // {
        //   title: '税额',
        //   dataIndex: 'TEX_AMOUNT',
        //   sorter: true,
        //   precision: 2,
        //   render: params => {
        //     return <span>{(params.row.IN_AMOUNT_TAXED - params.row.IN_AMOUNT).toFixed(2)}</span>;
        //   },
        //   filter: false,
        //   filterType: 'number'
        // },
        // {
        //   title: '发票号',
        //   sorter: true,
        //   width: 130,
        //   dataIndex: 'V_INVOICE_NO',
        //   editable: true,
        //   defaultEditable: true,
        //   editType: 'text',
        //   filter: false,
        //   filterType: 'input',
        //   render: params => {
        //     return <el-input disabled={!!params.row.ITEM_ID && params.row.ITEM_ID != 'N'} value={params.row.V_INVOICE_NO} size="small" onInput={e => (params.row.V_INVOICE_NO = e)}></el-input>;
        //   }
        // },
        {
          title: '来源方式',
          sorter: true,
          dataIndex: 'FROM_TYPE',
          render: props => {
            return <span>{this.createDictText(props.row.FROM_TYPE, '8088')}</span>;
          },
          filter: false,
          filterType: 'checkbox',
          filterItems: this.createDictList('8088')
        },
        {
          title: '发运单号',
          sorter: true,
          dataIndex: 'ORDER_NO'
        }
        // {
        //   title: '原采购入库单',
        //   sorter: true,
        //   dataIndex: 'OLD_STOCK_IN_NO',
        //   filter: false,
        //   filterType: 'input'
        // }
      ];
    },
    // table数据变化
    onTableDataChange(e) {
      this.dataSource = e;
    },
    // table行项选中变化
    handleTableRowSelectChange(e) {
      this.selectedTableRowData = e;
      if (this.selectedTableRowData.length > 0) {
        this.showDeleteBtn = false;
      } else {
        this.showDeleteBtn = true;
      }
      // this.showDeleteBtn = this.selectedTableRowData.length == 0;
    },
    // 获取明细的方法
    async queryThreeTypeOrderDetail(val) {
      this.$refs.table.START_LOADING();
      let orderType = this.orderType;
      let orderNo = this.orderNo;
      console.log(orderNo, 'orderNo::::');
      if (val[0].BSYSDH) {
        let orderIds = val.map(x => x.id);
        console.log(val, 'queryThreeTypeOrderDetailVal:::');
        orderNo = orderIds;
      }
      const res = await queryThreeTypeOrderDetail({
        orderType: orderType,
        orderNo: orderNo
      });
      console.log(res, 'res.data');
      this.$refs.table.STOP_LOADING();
      if (res.resultCode == '200') {
        // var defaultStorage = this.list.find(item => item.fieldName == 'defaultStorage').initialValue;
        if (this.orderType === 80881004) {
          // 判断是否存在
          // const flag = this.dataSource.find(item => {
          //   return item['PART_NO'] === res.data[0]['PART_NO'];
          // });
          // if (flag) {
          //   this.$notify({
          //     title: '警告',
          //     message: '信息已存在',
          //     type: 'warning'
          //   });
          //   return;
          // }
          this.isShowcaigou = false;
          this.saveBtnDisabled = false;
          this.orderNo = val[0].orderNo;
          this.list.find(x => x.fieldName === types.settle).initialValue = val[0].orderNo;
          res.data.map(item => {
            if (item.STORAGE_CODE == '' || item.STORAGE_CODE == null || item.STORAGE_CODE == undefined) {
              // item.STORAGE_CODE = defaultStorage || '';
            }
          });
          this.dataSource = res.data;
          // this.$refs.table.EXECUTE_INSERT(res.data);
        } else {
          res.data.map(item => {
            if (item.STORAGE_CODE == '' || (item.STORAGE_CODE == null && item.STORAGE_CODE == undefined)) {
              // item.STORAGE_CODE = defaultStorage || '';
            }
          });
          if (getAppId() == 'beijing' && res.data[0] && res.data[0].PART_TYPE == '50001001') {
            this.list.find(x => x.fieldName == types.customerCode).initialValue = '北京汽车销售有限公司';
            this.list.find(x => x.fieldName == 'name').initialValue = '北京汽车销售有限公司';
            this.list.find(x => x.fieldName == 'name').disabled = true;
          } else if (getAppId() == 'beijing' && res.data[0] && res.data[0].PART_TYPE == '50001002') {
            this.list.find(x => x.fieldName == types.customerCode).initialValue = '北京新能源汽车营销有限公司';
            this.list.find(x => x.fieldName == 'name').initialValue = '北京新能源汽车营销有限公司';
            this.list.find(x => x.fieldName == 'name').disabled = true;
          }
          this.dataSource = res.data;
          // this.$refs.table.EXECUTE_INSERT(res.data);
        }
      } else if (res.resultCode == '403') {
        this.$notify({
          title: '提示',
          message: res.errMsg,
          type: 'error'
        });
      }
    },
    // 数据改变的时候的方法
    onCellChange(val1, val2) {
      console.log('表单数据改变', val1, val2);

      //  if () {
      //   this.dataSource[val2.$index].STORAGE_POSITION_CODE = ""
      //  }
      //  if (val2.STORAGE_CODE != null&&val2.STORAGE_CODE != '' &&val2.PART_NO != null &&val2.PART_NO != '') {
      //     this.queryUsableLocations (val2)
      //  }
    },
    // 查库位的方法
    // async queryUsableLocations (val) {
    // const res = await  queryUsableLocations ( { storageCode: val.STORAGE_CODE, partNo: val.PART_NO })
    // if (res.data.length == 0) {
    // this.columns.find(x => x.dataIndex === 'STORAGE_POSITION_CODE').editItems = []
    // } else {
    // this.columns.find(x => x.dataIndex === 'STORAGE_POSITION_CODE').editItems = res.data.map(x => ({ text: x['storagePositionCode'], value: x['storagePositionCode'] }));
    // }
    // },
    // 发货单传的值
    confirmFahuodan(val) {
      if (val.length > 0) {
        // 判断是否存在
        const flag = this.dataSource.find(item => {
          return item['BILL_NO'] === val[0]['BILL_NO'];
        });
        if (flag) {
          this.$notify({
            title: '警告',
            message: '已经添加发货单信息,无法再次添加',
            type: 'warning'
          });
          return;
        }

        this.isShowfahuodan = false;
        this.saveBtnDisabled = false;
        let orderIds = val.map(x => x.BSYSDH).join(',');
        this.orderNo = orderIds;
        this.list.find(x => x.fieldName === types.settle).initialValue = orderIds;
        console.log(val, 'confirmFahuodanVal::');
        this.fahuodanData = Object.assign({}, val[0], { id: val[0].id + '' });
        this.queryThreeTypeOrderDetail(val);
        this.columns.find(x => x.dataIndex == 'STORAGE_CODE').disabled = true;
      } else {
        this.$notify({
          title: '警告',
          message: '您还未选择数据',
          type: 'warning'
        });
      }
    },
    // 税率改变的时候执行的方法
    handleTax(val) {
      let sl = Number(val);
      console.log('税率', sl);
      // row['IN_QUANTITY'] = -row['IN_QUANTITY'];  参考
      // row['IN_AMOUNT'] = -row['IN_AMOUNT'];
      // row['IN_AMOUNT_TAXED'] = -row['IN_AMOUNT_TAXED'];
      this.dataSource.forEach((item, index) => {
        // 数量
        let IN_QUANTITY = Number(item.IN_QUANTITY);
        // 入库 不含税单价
        let IN_PRICE_TAXED = Number(item.IN_PRICE_TAXED);
        // 入库含税单价
        let IN_PRICE = (Number(IN_PRICE_TAXED) / (sl + 1)).toFixed(4);
        item.IN_PRICE_TAXED = IN_PRICE_TAXED;
        // 入库不含税金额
        let IN_AMOUNT = (Number(IN_QUANTITY) * Number(IN_PRICE)).toFixed(2);
        item.IN_AMOUNT = IN_AMOUNT;
        // 入库含税金额
        let IN_AMOUNT_TAXED = (Number(IN_QUANTITY) * Number(IN_PRICE_TAXED)).toFixed(2);
        item.IN_AMOUNT_TAXED = IN_AMOUNT_TAXED;
        item.IN_QUANTITY = Number(IN_QUANTITY).toFixed(2);
        item.IN_PRICE = Number(IN_PRICE).toFixed(4);
      });
      // this.list.find(x => x.fieldName == types.tax).initialValue = sl;
    },
    // 交易平台传的值
    confirmJiaoyipingtai(val) {
      if (val.length > 0) {
        // 判断是否存在
        const flag = this.dataSource.find(item => {
          return item['PART_NO'] === val[0]['PART_NO'];
        });
        if (flag) {
          this.$notify({
            title: '警告',
            message: '信息已存在',
            type: 'warning'
          });
          return;
        }
        // 交易平台需要先计算不含税单价
        val.forEach(item => {
          item.IN_PRICE = item.IN_PRICE_TAXED / (1 + (+this.tax || 0.13));
        });
        this.isShowjiaoyipingtai = false;
        this.saveBtnDisabled = false;
        this.$refs.table.$refs.pageTable.EXECUTE_INSERT(val);
        this.$notify({
          title: '提示',
          message: '信息添加成功',
          type: 'success'
        });
      } else {
        this.$notify({
          title: '警告',
          message: '您还未选择数据',
          type: 'warning'
        });
      }
    },
    // 采购订单传的值
    confirmCaigou(val) {
      if (val.length > 0) {
        this.dataSource = [];
        this.orderNo = val[0].orderNo;
        this.queryThreeTypeOrderDetail(val);
      } else {
        this.$notify({
          title: '警告',
          message: '您还未选择数据',
          type: 'warning'
        });
      }
    },
    // 同步提示确认
    async confirmTongBu(rowData) {
      let row = JSON.parse(JSON.stringify(rowData));
      let partNos = '';
      // for (let i = 0; i < row.length; i++) {
      //   partNos += ",'" + row[i].partNo + "'";
      // }
      // console.log('partNos', partNos);
      // if (partNos.length > 1) {
      //   partNos = partNos.substring(1, partNos.length);
      // }
      partNos =
        "'" +
        row
          .map(item => {
            return item.partNo;
          })
          .join("','") +
        "'";
      console.log('partNos::', partNos);
      console.log('aaaaa::', { partNos: partNos });
      let res = await updatePartInfoByPartNos({ partNos: partNos });
      let susPart = '';
      let failPart = '';
      console.log('res::', res);
      if (res.resultCode == 200 && res.data) {
        for (let i = 0; i < row.length; i++) {
          for (let j = 0; j < res.data.length; j++) {
            if (row[i].partNo == res.data[j].PART_NO) {
              susPart += row[i].partNo + ',';
              continue;
            }
          }
        }
        if (susPart.length == 0) {
          row.forEach(item => {
            failPart += item.partNo + ',';
          });
        }
        let message = '';
        if (susPart != '') {
          message = susPart.substring(0, susPart.length - 1) + '更新成功  ';
        }
        if (failPart != '') {
          message += failPart.substring(0, failPart.length - 1) + '更新失败，可能暂无配件r3价格';
        }
        this.$notify({
          title: '提示',
          message: message,
          type: 'success'
        });
        this.jiaGeTiShiData.forEach(item => {
          res.data.find(obj => {
            if (obj.MATNR === item.partNo) {
              item.KBETR = obj.KBETR;
              item.EP_IN_PRICE = obj.KBETR;
            }
          });
        });
        console.log(this.jiaGeTiShiData);
      }
    },
    // 文化公司传的值
    confirmWenhua() {
      if (val.length > 0) {
        this.isShowjiaoyipingtai = false;
        this.$notify({
          title: '提示',
          message: '信息添加成功',
          type: 'success'
        });
        this.orderNo = val.orderNo;
        this.queryThreeTypeOrderDetail(val);
      } else {
        this.$notify({
          title: '警告',
          message: '您还未选择数据',
          type: 'warning'
        });
      }
    },
    formChange(p) {
      console.log('formChange', p);
      // this.saveBtnClick()
    },
    // 打印销售单
    async handleDayin() {
      console.log(this.printdataList, 'this.printdataList');
      this.dy = true;
      let printParams = '';
      // 获取打印参数
      // try {
      //   printParams = await queryPartinventoryPrintParam();
      // } catch (err) {
      //   console.log('获取入库打印参数失败', err);
      // }
      const res = await printData(this.cunPrintid, printParams ? printParams.data[0].bParaValue : 0);
      this.SalesprintList = res.data;
      this.SalesprintList.baseInfo.STOCK_IN_TYPE = '采购入库-' + this.createDictText(this.SalesprintList.baseInfo.STOCK_IN_TYPE, '8088'); // 修改出入库类型为采购入库
      // this.SalesprintList.baseInfo.STOCK_IN_TYPE = ;
      this.SalesprintList.baseInfo.FINISHED_TYPE = '入库时间'; // 修改领料时间为->入库时间
      this.cunUserList.forEach(x => {
        if (this.SalesprintList.baseInfo.USER_ID == x.userId) {
          this.SalesprintList.baseInfo.USER_NAME = x.employeeName;
        }
      });
      // this.SalesprintList.baseInfo.USER_ID
      // 打印
      this.$nextTick(() => {
        this.$refs.Salesprint.EXCUTE_PRINT();
      });
    },
    // 新建
    newBtnClick() {
      // 新建时入库类型默认为发货单业务往来客户默认为一汽
      this.list.find(item => item.fieldName == types.stockInType).initialValue = 80881003;
      // this.setDefaultDealerToVw();
      this.orderType = 80881003;
      this.setPageState(pageStateTypes.new);
      this.setPageState(pageStateTypes.fahuodan);
    },
    // 删除按钮事件
    deleteBtnClick(props) {
      if (this.saveBtnDisabled == true) {
        Util.notifyAction('已入库，无法删除', 'warning');
        return;
      }
      // console.log('删除按钮', props);
      Util.confirmAction('是否确认删除此配件？')
        .then(confirm => {
          this.deleteRows.push(this.selectedTableRowData);
          this.selectedTableRowData.map(item => {
            if (item.ITEM_ID != null && item.ITEM_ID != undefined && item.ITEM_ID != '') {
              this.shanchu.push(item.ITEM_ID);
            }
          });
          this.$refs.table.EXECUTE_DELETE(this.deleteRows);
          // const index = props.row.$index;
          // const [row] = this.dataSource.splice(index, 1);
          this.newBtnDisabled = true; // 新建
          this.saveBtnDisabled = false; // 保存
          this.bookedBtnDisabled = true; // 入账
          this.cancelBtnDisabled = false; // 取消
          this.deleteWholeList = false; // 删除整单
          this.showDeleteBtn = false; // 删除数据
          this.prindfBtnDisabled = true; // 打印
          if (this.dataSource.length == 0) {
            this.bookedBtnDisabled = true;
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 删除整单事件
    async deleteWholeListClick() {
      if (!this.getFormListValue(types.stockInNo) || this.getFormListValue(types.stockInNo).length <= 0) {
        this.$notify.warning({ title: '提示信息', message: '删除整单只能删除已保存单据!' });
        return;
      }
      try {
        console.log('sdfsdfsfsdfsf');
        this.$confirm('您确定要删除整单吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          console.log(this.getFormListValue(types.stockInNo));
          let sin = null;
          if (this.getFormListValue(types.stockInNo) != 'stockInNo' && this.getFormListValue(types.stockInNo) != '') {
            sin = this.getFormListValue(types.stockInNo);
            console.log('sin:' + sin);
          }
          let res = await deleteWholeListClickMethod(sin);
          if (res.resultCode == 200) {
            this.$notify.success({ title: '提示信息', message: '删除成功!' });
            this.cancelBtnClick();
          }
        });
      } catch (e) {}
    },
    // async partgetfourData () {
    //   let params = {}
    //   params.orderType  = '80881003'
    //   params.orderNo = ''
    //   const res = await partgetfourData (params)
    // },
    // handleSave () {
    //  this.$refs.form.SUBMIT_FORM()
    // },
    async saveBtnClick(row, isSub) {
      if (this.dataSource.length == 0) {
        this.$notify({
          title: '警告',
          message: '数据为空不能保存',
          type: 'warning'
        });
        return;
      }
      if (!this.getFormListValue(types.customerCode)) {
        this.$notify({
          title: '警告',
          message: '业务往来客户未选择',
          type: 'warning'
        });
        return;
      }
      if (!this.getFormListValue(types.stockInType)) {
        this.$notify({
          title: '警告',
          message: '入库类型未选择',
          type: 'warning'
        });
        return;
      }
      console.log(this.ckDataList, '保存'); // OEM_TAG 10451002原厂 IS_ACTIVITY_PART == X

      // 判断配件是否符合规则
      let xuhao = 0;
      let canku = true;
      let kuwei = true;
      let shuliang = true;
      let limitFlag = true;
      let limitFalseArr = [];
      let xuhaoFor = '';
      let unconventionalAvtivePartList = []; // 校验手工入库只有活动件能入原厂库
      let unconventionalPartTypePartList = []; // 校验配件类型和所入仓库类型
      let orderStockInType = this.getFormListValue(types.stockInType); // 入库类型
      let a = this.dataSource.map(item => {
        const item2 = Object.assign({}, item);
        const returnObj = Util.camelCaseObject(item2);
        // 测试编辑
        // returnObj.flag = 'U'
        return returnObj;
      });
      this.dataSource.forEach(x => {
        if (x.STORAGE_CODE == '' || x.STORAGE_CODE == null) {
          canku = false;
        }
        if (x.STORAGE_POSITION_CODE == '' || x.STORAGE_POSITION_CODE == null) {
          kuwei = false;
          xuhao = x.$index + 1;
          xuhaoFor += xuhao + ' , ';
        }
        if (x.IN_QUANTITY == 0) {
          shuliang = false;
        }
        if (x.LIMIT_QUANTITY !== undefined && x.LIMIT_QUANTITY !== null && x.LIMIT_QUANTITY !== '') {
          if (parseFloat(x.IN_QUANTITY) > x.LIMIT_QUANTITY) {
            limitFlag = false;
            limitFalseArr.push(x.$index + 1);
          }
        }
        // 手工入库校验入原厂库的配件是否是活动件
        if (orderStockInType == '80881001') {
          let stockIsOem = this.ckDataList.find(item => item.STORAGE_CODE == x.STORAGE_CODE) ? this.ckDataList.find(item => item.STORAGE_CODE == x.STORAGE_CODE).OEM_TAG == 10451002 : false;
          stockIsOem && x.IS_ACTIVITY_PART != 'X' && unconventionalAvtivePartList.push(x.$index + 1);
        }
        let stockType = this.ckDataList.find(item => item.STORAGE_CODE == x.STORAGE_CODE) ? this.ckDataList.find(item => item.STORAGE_CODE == x.STORAGE_CODE).STORAGE_TYPE != x.PART_TYPE : false;
        console.log(x, 'x::::');
        stockType && unconventionalPartTypePartList.push(x.$index + 1);
      });
      if (!canku) {
        this.$notify({
          title: '警告',
          message: '仓库未选择',
          type: 'warning'
        });
        return;
      }
      if (!kuwei) {
        this.$notify({
          title: '警告',
          message: '行项：' + xuhaoFor + '  库位不能为空',
          type: 'warning'
        });
        return;
      }
      if (!shuliang) {
        this.$notify({
          title: '警告',
          message: '配件数量为0不能保存或入账',
          type: 'warning'
        });
        return;
      }
      if (!limitFlag) {
        this.$notify({
          title: '警告',
          message: '入库数量不能大于最大入库数量，不符合的行项：' + limitFalseArr.join(','),
          type: 'warning'
        });
        return;
      }
      if (unconventionalAvtivePartList.length) {
        return this.$notify({
          title: '警告',
          message: '外采入库只能入非原厂库，不符合规则的配件行项：' + unconventionalAvtivePartList.join(','),
          type: 'warning'
        });
      }
      if (unconventionalPartTypePartList.length) {
        return this.$notify({
          title: '警告',
          message: '相应类型配件只能入相应类型仓库，不符合规则的配件行项：' + unconventionalPartTypePartList.join(','),
          type: 'warning'
        });
      }
      // let saveTax = this.list.find(item => item.fieldName == 'tax').initialValue;

      const params = {
        remark: this.getFormListValue(types.remark),
        customerCode: this.getFormListValue(types.customerCode),
        customerName: this.customerName,
        dms_table: this.dataSource.map(item => {
          const item2 = Object.assign({}, item);
          const returnObj = Util.camelCaseObject(item2);
          // 测试编辑
          // returnObj.flag = 'U'
          return returnObj;
        }),
        // operator: '9995',
        // priceAddRate: '0',
        stockInNo: this.getFormListValue(types.stockInNo),
        sheetCreateDate: this.getFormListValue(types.sheetCreateDate),
        stockInType: this.getFormListValue(types.stockInType),
        tax: this.tax,
        // 新增保存入参单号
        purchaseCode: this.orderNo
      };
      if (this.shanchu.length > 0) {
        params.items = this.shanchu.join(',');
      }
      params.dms_table.forEach(x => {
        if (x.itemId != '' && x.itemId != null && x.itemId != undefined && x.itemId != 'N') {
          x.flag = 'X';
        } else {
          x.flag = 'A';
          x.itemId = 'N';
        }
        x.unit = x.UNIT;
      });
      console.log('参数', params);
      let array = '';
      if (params.dms_table.length > 0) {
        params.dms_table.find(x => {
          if (x.inPriceTaxed == 0) {
            array = array + ',' + x.partNo;
          }
          if (!x.inAmountTaxed) {
            x.inAmountTaxed = x.inPriceTaxed * x.inQuantity;
          }
          x.inPrice = x.inPriceTaxed / 1.13;
          x.inAmount = x.inAmountTaxed / 1.13;
        });
        if (array.length > 0) {
          array = array.substring(1, array.length);
          await confirmAction('配件' + array + '的入库含税单价为0，确定执行保存?');
        }
        if (this.orderType == '80881009') {
          console.log(this.isCheck, ':::');
          if (this.isCheck == 0 || this.isCheck == 3) {
            params.isCheck = 1;
          } else {
            params.isCheck = 0;
          }
        }
        const saveRes = await partbuySave(params);
        console.log('保存', saveRes);
        if (saveRes.resultCode == 200 && saveRes.data) {
          this.$notify({
            title: '提示',
            message: '保存成功',
            type: 'success'
          });
          this.deleteWholeList = false;
          // 保存成功重新复制表单与table数据并修改编辑状态
          this.list.find(x => x.fieldName === types.stockInNo).initialValue = saveRes.data;
          // this.saveBtnDisabled = true;
          this.bookedBtnDisabled = false;
          // this.list.find(x => x.fieldName === types.stockInType).disabled = true;
          // this.list.find(x => x.fieldName === types.customerCode).disabled = true;
          // this.list.find(x => x.fieldName == types.tax).disabled = true;
          this.list.map(item => (item.disabled = true));
          this.isCheck = params.isCheck;
          const res = await partbuyStockInItem({ stockInNo: saveRes.data });
          this.stockIn(saveRes.data);
          this.dataSource = res.data;
          this.shanchu = [];
          console.log('查询的单号', this.dataSource);
          // 获取打印数据的方法
          // this.dayinHandleTop();
          // 是否同步采购价
          // this.jiaGeTiShiData = [];
          // console.log('this.getFormListValue(types.stockInType)::', this.getFormListValue(types.stockInType));
          // if (this.getFormListValue(types.stockInType) === 80881003) {
          //   console.log('start------');
          //   let partNos = '';
          //   // console.log('params.dms_table.length::', params.dms_table.length);
          //   // for (let i = 0; i < params.dms_table.length; i++) {
          //   //   partNos += ",'" + params.dms_table[i].partNo + "'";
          //   // }
          //   // if (partNos.length > 1) {
          //   //   partNos = partNos.substring(1, partNos.length);
          //   // }
          //   partNos =
          //     "'" +
          //     params.dms_table
          //       .map(item => {
          //         return item.partNo;
          //       })
          //       .join("','") +
          //     "'";
          //   console.log('partNos', partNos);
          //   const EPdataIn = await getPartInfo(partNos);
          //   console.log('EPdata::', EPdataIn);
          //   let EPdata = EPdataIn.data;
          //   console.log('EPdata::', EPdata);
          //   for (let i = 0; i < EPdata.length; i++) {
          //     let planPrice = Number(EPdata[i].PLAN_PRICE).toFixed(2);
          //     for (let j = 0; j < params.dms_table.length; j++) {
          //       let inPrince = Number(params.dms_table[j].inPrice).toFixed(2);
          //       if (EPdata[i].PART_NO === params.dms_table[j].partNo && planPrice != inPrince) {
          //         params.dms_table[j].EP_IN_PRICE = planPrice;
          //         params.dms_table[j].DIFFERENT_PRICE = inPrince - planPrice;
          //         params.dms_table[j].inPrice = inPrince;
          //         console.log('obj:::', params.dms_table[j]);
          //         this.jiaGeTiShiData.push(params.dms_table[j]);
          //         this.flagTB = true;
          //       }
          //     }
          //   }
          //   console.log('this.jiaGeTiShiData', this.jiaGeTiShiData);
          //   if (this.flagTB) {
          //     this.isShowTongBu = true;
          //     this.flagTB = false;
          //   }
          // }
        }
      } else {
        this.$notify({
          title: '警告',
          message: '清单不能为空！',
          type: 'warning'
        });
      }
    },
    bookedBtnClick() {
      // console.log('入账');
      // this.isShowBookedTipPanel = true;
      Util.confirmAction('此操作将入账本入库单，是否继续')
        .then(confirm => {
          this.confirmBookedTipPanel();
        })
        .catch(err => {
          console.log(err);
        });
    },
    cancelBtnClick() {
      console.log('取消');
      this.dataSource = [];
      this.deleteRows = [];
      this.fahuodanData = {};
      this.storagePositionList = {};
      this.setPageState(pageStateTypes.none);
      this.list.find(x => x.fieldName == 'tax').disabled = true;
      this.customerName = '';
      this.orderNo = '';
      this.isFinished = false;
      this.orderType = null;
      this.isCheck = null;
    },
    // 表格 编辑按钮
    tableCellEditClick(props) {
      this.selectRowEdit = Object.assign({}, props.row, { $index_edit: props.row.$index });
      console.log('表格 编辑按钮', this.selectRowEdit);
      if (this.getFormListValue(types.stockInType) == '80881001') {
        // 手工入库
        this.isShowEditPanel = true;
      } else if (this.getFormListValue(types.stockInType) == '80881002') {
        // 采购退货
        this.showConfirmReturnEditPanel(this.selectRowEdit);
      } else if (this.getFormListValue(types.stockInType) == '80881003') {
        // 发货单
        this.EditFahuodan = true;
      } else if (this.getFormListValue(types.stockInType) == '80881004') {
        // 采购订单
        this.EditCaigou = true;
      } else if (this.getFormListValue(types.stockInType) == '80881005') {
        // 交易平台
        this.EditJiaoyipingtai = true;
      } else if (this.getFormListValue(types.stockInType) == '80881006') {
        // 文化公司
        this.EditWenhua = true;
      }
    },
    /**  */
    // 入库单号
    showSearchOrder() {
      this.isShowSearchOrder = true;
    },
    async confirmSearchOrder(row) {
      console.log('选择的入库单号', row);
      this.isShowSearchOrder = false;
      this.isCheck = row.IS_CHECKED;
      this.orderType = row.STOCK_IN_TYPE;
      // 回显信息
      await this.setPageState(pageStateTypes.add_edit);
      this.list.find(x => x.fieldName === types.stockInNo).initialValue = row['STOCK_IN_NO'];
      this.list.find(x => x.fieldName === types.customerCode).initialValue = row['CUSTOMER_CODE'];
      this.list.find(x => x.fieldName === types.customerCode).initialValue = row['CUSTOMER_CODE'];
      this.list.find(x => x.fieldName === 'name').initialValue = row['CUSTOMER_NAME'];
      this.customerName = row['CUSTOMER_NAME'];
      // this.list.find(x => x.fieldName === types.priceAddRate).initialValue = row['PRICE_ADD_RATE'];
      // this.list.find(x => x.fieldName === types.tax).initialValue = row['TAX'] ? row['TAX'] : this.tax;
      this.list.find(x => x.fieldName === types.stockInType).initialValue = row['STOCK_IN_TYPE'];
      this.list.find(x => x.fieldName === types.sheetCreateDate).initialValue = moment(row['ORDER_DATE']).format('YYYY-MM-DD');
      this.list.find(x => x.fieldName === types.remark).initialValue = row['REMARK'];
      // 单号选择
      this.list.find(x => x.fieldName === types.settle).initialValue = row['PURCHASE_CODE'];
      // 查询明细 显示到表格
      const res = await partbuyStockInItem({ stockInNo: row['STOCK_IN_NO'] });
      console.log('查询的单号', res);
      this.dataSource = res.data;
      // this.bookedBtnDisabled = false; // 现有入库单能够直接入库
      console.log(row['STOCK_IN_TYPE'], '80881001');
      this.addBtnDisabled = false;
      // if (row['STOCK_IN_TYPE'] == '80881001') {
      //   this.addBtnDisabled = false;
      // }
      // 发货单入库赋值签收用数据
      if (row['STOCK_IN_TYPE'] == '80881003') {
        this.fahuodanData.id = '';
        this.fahuodanData.vbeln = row.PURCHASE_CODE;
        this.columns.find(x => x.dataIndex == 'STORAGE_CODE').disabled = true;
        this.addBtnDisabled = true;
        console.log(this.columns.find(x => x.dataIndex == 'STORAGE_CODE').disabled, 'disabled::');
        this.columns.find(x => x.dataIndex == 'IN_PRICE_TAXED').disabled = true;
      }

      if (this.orderType == '80881009') {
        this.addBtnDisabled = true;
        if (this.isCheck == 2) {
          this.bookedBtnDisabled = false;
          this.columns.find(x => x.dataIndex == 'IN_PRICE_TAXED').disabled = true;
        }
      }
    },
    // 客户选择
    showSearchCustomer() {
      this.isShowSearchCustomer = true;
    },
    confirmSearchCustomer([row]) {
      console.log('客户选择 这里有业务往来客户代码', row);
      this.list.find(x => x.fieldName === types.customerCode).initialValue = row['CUSTOMER_CODE'];
      this.list.find(x => x.fieldName === 'name').initialValue = row['CUSTOMER_NAME'];
      this.customerName = row['CUSTOMER_NAME'];
      // this.list.find(x => x.fieldName === 'wanglaikehu').initialValue = row['CUSTOMER_NAME'];
      // this.list.find(x => x.fieldName === 'tax').initialValue = row['TAX'] ? row['TAX'] : this.tax;
      this.isShowSearchCustomer = false;
    },
    // 采购入库新增
    showAddPanel() {
      if (!this.getFormListValue(types.customerCode)) {
        this.$notify({
          title: '警告',
          message: '请先填写业务往来客户',
          type: 'warning'
        });
        return;
      }
      if (!this.getFormListValue(types.stockInType)) {
        this.$notify({
          title: '警告',
          message: '入库类型未选择',
          type: 'warning'
        });
        return;
      }
      this.isShowAddPanel = true;
    },
    confirmAddPanel(row) {
      console.log('confirmAddPanel新增', row);
      // 先赋值默认仓库
      // let defaultStorageCode = this.list.find(item => item.fieldName == 'defaultStorage').initialValue;
      if (row.STORAGE_CODE == undefined || row.STORAGE_CODE == null || row.STORAGE_CODE == '') {
        // row.STORAGE_CODE = defaultStorageCode || '';
      }
      // 判断配件是否存在
      let canku = false;
      let flag = false;
      this.dataSource.forEach(x => {
        if (x['PART_NO'] === row['PART_NO']) {
          flag = true;
        }
        if (x['STORAGE_CODE'] === row['STORAGE_CODE']) {
          canku = true;
        }
      });
      if (flag) {
        this.$notify({
          title: '警告',
          message: '配件已存在',
          type: 'warning'
        });
        return;
      }
      row.flag = 'A';
      row.itemId = 'N';
      if (row.UNIT_CODE != undefined && row.UNIT_CODE != null && row.UNIT_CODE != '') {
        row.UNIT = row.UNIT_CODE;
      }
      this.CKFlag = null;
      this.$refs.table.EXECUTE_INSERT(row);
      // this.dataSource = [...this.dataSource];
      if (row.closeShow != false) {
        this.$notify({
          title: '提示',
          message: '新增成功',
          type: 'success'
        });
      }
      if (row.closeShow == false) {
        this.isShowAddPanel = false;
      }
      console.log(row.closeShow, 'row.closeShow');
      this.saveBtnDisabled = false;
    },
    confirmEditPanel(val) {
      console.log('编辑', val);
      // 这里应该itemid来判断

      if (val.ITEM_ID != 'N' && val.ITEM_ID != null && val.ITEM_ID != '' && val.ITEM_ID != undefined) {
        // if (this.list.find(x => x.fieldName === types.stockInNo).initialValue === '' || this.list.find(x => x.fieldName === types.stockInNo).initialValue === null) {
        //  val.flag = 'A';
        //  val.itemId = 'N';
        val.flag = 'X';
      } else {
        val.flag = 'A';
        val.ITEM_ID = 'N';
        //  val.flag = 'X';
      }
      if (val.unitCode) {
        val.UNIT = val.unitCode;
      }
      this.dataSource[val.$index_edit] = val;
      // this.dataSource[val.$index_edit] = Object.assign({}, val);
      // this.dataSource = [...this.dataSource];
      // 按钮状态需要改变
      this.newBtnDisabled = true; // 新建
      this.saveBtnDisabled = false; // 保存
      this.bookedBtnDisabled = true; // 入账
      this.cancelBtnDisabled = false; // 取消
      this.deleteWholeList = false; // 删除整单
      this.showDeleteBtn = false; // 删除数据
      this.prindfBtnDisabled = true; // 打印
      this.isShowEditPanel = false;
      this.dataSource = [...this.dataSource];
    },
    // 发货单
    showFahuodan() {
      this.isShowfahuodan = true;
    },
    // 采购订单
    showCaigou() {
      this.isShowcaigou = true;
    },
    // 交易平台
    showJiaoyipingtai() {
      this.isShowjiaoyipingtai = true;
    },
    // 文化公司
    showWenhua() {
      // this.isShowwenhua = true
      this.$notify({
        title: '提示',
        message: '暂无该功能',
        type: 'warning'
      });
    },
    // 采购退货
    showReturnPanel() {
      if (!this.getFormListValue(types.customerCode)) {
        this.$notify({
          title: '警告',
          message: '请先填写业务往来客户',
          type: 'warning'
        });
        return;
      }
      if (!this.getFormListValue(types.stockInType)) {
        this.$notify({
          title: '警告',
          message: '入库类型未选择',
          type: 'warning'
        });
        return;
      }
      this.isShowReturnPanel = true;
    },
    confirmReturnPanel(row) {
      console.log('退货 确定', row);
      if (this.dataSource.length == 0) {
        // 退货 计算 数量 不含税金额 含税金额
        row.forEach(x => {
          x.flag = 'A';
          x.itemId = 'N';
          x['IN_QUANTITY'] = -x['IN_QUANTITY'];
          x['IN_AMOUNT'] = -x['IN_AMOUNT'];
          x['IN_AMOUNT_TAXED'] = -x['IN_AMOUNT_TAXED'];
        });
        // 表格添加一条数据
        this.$refs.table.$refs.pageTable.EXECUTE_INSERT(row);
        this.$notify.success({
          title: '提示',
          message: '添加成功'
        });
        this.list.find(x => x.fieldName === 'tax').initialValue = row[0].TAX || 0.13;
        this.list.find(x => x.fieldName === 'tax').disabled = true;
        this.tax = row[0].TAX || 0.13;
        this.saveBtnDisabled = false;
      } else {
        let flag1 = false;
        let flag2 = false;
        this.dataSource.forEach(item => {
          row.forEach(x => {
            if (item['STOCK_IN_NO'] === x['STOCK_IN_NO']) {
              flag1 = true;
            }
            if (item['PART_NO'] === x['PART_NO']) {
              flag2 = true;
            }
            if (flag1 && flag2) {
              this.flagPd = true;
            }
          });
        });
        if (this.flagPd) {
          this.$notify({
            title: '警告',
            message: '配件已存在',
            type: 'warning'
          });
          this.flagPd = false;
          return;
        }
        // 退货 计算 数量 不含税金额 含税金额
        row.forEach(x => {
          x.flag = 'A';
          x.itemId = 'N';
          x['IN_QUANTITY'] = -x['IN_QUANTITY'];
          x['IN_AMOUNT'] = -x['IN_AMOUNT'];
          x['IN_AMOUNT_TAXED'] = -x['IN_AMOUNT_TAXED'];
        });
        // 表格添加一条数据
        this.$refs.table.$refs.pageTable.EXECUTE_INSERT(row);
        this.$notify.success({
          title: '提示',
          message: '添加成功'
        });
        this.saveBtnDisabled = false;
      }
    },
    async showConfirmReturnEditPanel(row) {
      console.log(row, '打印的数据');
      const params = {
        OLD_STOCK_IN_NO: row.OLD_STOCK_IN_NO,
        PART_NO: row.PART_NO,
        STORAGE_CODE: row.STORAGE_CODE,
        RETURN_ITEM_ID: row.RETURN_ITEM_ID
      };
      const res = await partbuyQueryCanReturnNum(params);
      console.log('查询可退货数', res);
      // const CAN_RETURN_QUANTITY = res.data.CAN_RETURN_QUANTITY; //可退货数
      // 组织数据
      this.partReturnEditFormData = row;
      this.partReturnEditFormData.IN_QUANTITY = -this.partReturnEditFormData.IN_QUANTITY;
      this.partReturnEditFormData.CAN_RETURN_QUANTITY = res.data.CAN_RETURN_QUANTITY; // 可退货数
      // this.partReturnEditFormData = {
      //   // STORAGE_CODE: '',
      //   IN_QUANTITY:-row.IN_QUANTITY, //入库数量
      //   STORAGE_NAME:row.STORAGE_NAME,  //仓库
      //   PART_NO: row.PART_NO,  //配件代码
      //   PART_NAME: row.PART_NAME, //配件名称
      //   CAN_RETURN_QUANTITY:CAN_RETURN_QUANTITY  //可退货数
      // };
      this.isShowReturnEditPanel = true;
    },
    confirmReturnEditPanel(val) {
      console.log('退货编辑 确定', val);
      // 旧 if (this.list.find(x => x.fieldName === types.stockInNo).initialValue === '' || this.list.find(x => x.fieldName === types.stockInNo).initialValue === null) {
      //  val.flag = 'A';
      //  val.itemId = 'N';
      // } else {
      //  val.flag = 'X';
      // }
      if (val.ITEM_ID != 'N' && val.ITEM_ID != null && val.ITEM_ID != '' && val.ITEM_ID != undefined) {
        // if (this.list.find(x => x.fieldName === types.stockInNo).initialValue === '' || this.list.find(x => x.fieldName === types.stockInNo).initialValue === null) {
        //  val.flag = 'A';
        //  val.itemId = 'N';
        val.flag = 'X';
      } else {
        val.flag = 'A';
        val.ITEM_ID = 'N';
        //  val.flag = 'X';
      }
      this.dataSource[val.$index] = val;
      this.isShowReturnEditPanel = false;
      this.dataSource = [...this.dataSource];
    },
    // 入账
    showPartReturn() {
      this.isShowBookedTipPanel = true;
    },
    confirmPartReturn() {
      this.isShowPartReturn = false;
    },
    // 入账提示
    async confirmBookedTipPanel() {
      // this.isShowBookedTipPanel = false;
      // console.log('入账');
      let shuliang = true;
      this.dataSource.forEach(x => {
        if (x.IN_QUANTITY == 0) {
          shuliang = false;
        }
      });
      if (!shuliang) {
        this.$notify({
          title: '警告',
          message: '配件数量为0不能保存或入账',
          type: 'warning'
        });
        return;
      }
      const params = {
        remark: this.getFormListValue(types.remark),
        stockInNo: this.getFormListValue(types.stockInNo),
        customerCode: this.getFormListValue(types.customerCode),
        customerName: this.customerName,
        stockInType: this.getFormListValue(types.stockInType),
        dms_table: this.dataSource.map(item => {
          const item2 = Object.assign({}, item);
          return Util.camelCaseObject(item2);
        }),
        // operator: '9995',
        // priceAddRate: '0',
        sheetCreateDate: this.list.find(x => x.fieldName === types.sheetCreateDate).initialValue
        // tax: this.list.find(x => x.fieldName === types.tax).initialValue
      };
      const res = await partbuyEnterRecord(params);
      if (res.resultCode == 200 && res.data) {
        // 上面的表单全部置灰
        this.list.find(x => x.fieldName === types.stockInNo).disabled = true;
        this.list.find(x => x.fieldName === types.customerCode).disabled = true;
        // this.list.find(x => x.fieldName === types.tax).disabled = true;
        this.list.find(x => x.fieldName === types.stockInType).disabled = true;
        // this.list.find(x => x.fieldName === 'defaultStorage').disabled = true;
        // this.list.find(x => x.fieldName === 'areaCode').disabled = true;
        this.list.find(x => x.fieldName === types.remark).disabled = true;
        this.list.find(x => x.fieldName === types.sheetCreateDate).disabled = true;
        this.list = [...this.list];
        // 获取打印数据的方法
        this.cunPrintid = res.data;

        this.$notify({
          title: '提示',
          message: '入库成功',
          type: 'success'
        });
        this.isShowBookedTipPanel = false;
        this.bookedBtnDisabled = true; // 入账按钮关闭
        this.saveBtnDisabled = true; // 保存按钮关闭
        this.addBtnDisabled = true; // 新增按钮关闭
        this.returnBtnDisabled = true; // 退货按钮关闭
        this.operateBtnDisabled = true; // 操作按钮关闭
        this.prindfBtnDisabled = false; // 打开打印按钮
        this.dcmbBtnDisabled = true; // 导出模板
        this.deleteWholeList = true; // 删除整单
        this.showDeleteBtn = true; // 删除数据
        this.drBtnDisabled = true; // 导入
        this.dcBtnDisabled = false; // 导出
        this.isFinished = true;
        // 入库成功后查询是否有关联欠料单
        try {
          let hansIndebtpartRes = await queryInventoryPartIsRelevanceInDebt({
            stockInNo: this.getFormListValue(types.stockInNo)
          });
          console.log(hansIndebtpartRes);
          if (hansIndebtpartRes.resultCode == 200 && hansIndebtpartRes.data.rows.length) {
            this.inDebtstockInNo = this.getFormListValue(types.stockInNo);
            this.inDebtVisible = true;
          }
        } catch (err) {
          console.log(err);
        }
        // console.log('获取打印数据', autoPrint == 'true');
        // if (autoPrint == 'true') {
        //   this.handleDayin();
        // }

        // 判断入库类型决定是否显示签收弹窗，发货单自动弹出签收, 判断是否自动打印 否则直接清空页面
        // let autoPrint = this.list.find(item => item.fieldName == 'autoPrint').initialValue;
        // let inventoryType = this.list.find(item => item.fieldName == types.stockInType).initialValue;
        // if (inventoryType == 80881003 || autoPrint == 'true') {
        //   autoPrint == 'true' && this.handleDayin();
        //   inventoryType == 80881003 && (this.signVisible = true);
        // } else {
        //   this.cancelBtnClick(); // 入库成功后重置页面AE-12347
        // }
      } else {
        this.isShowBookedTipPanel = false;
      }
    },
    async printData(data) {
      // 传单号
      const res = await printData(data);
      this.printdataList = res.data;
    },
    // 获取打印数据
    // async dayinHandle() {
    //   const res = await partbuyStockInItem({ stockInNo: this.list.find(x => x.fieldName === types.stockInNo).initialValue });
    //   this.dyList = res.data;
    // },
    // async dayinHandleTop() {
    //   const res = await stockIn({ stockInNo: this.list.find(x => x.fieldName === types.stockInNo).initialValue });
    //   this.dyListTop = res.data.rows;
    // },
    // 货运单选择
    showGoodsOrder() {
      this.isShowGoodsOrder = true;
    },
    confirmGoodsOrder() {
      this.isShowGoodsOrder = false;
    },
    // 编辑发货单 确定方法
    confirmEditFahuodan(val) {
      // 旧 if (this.list.find(x => x.fieldName === types.stockInNo).initialValue === '' || this.list.find(x => x.fieldName === types.stockInNo).initialValue === null) {
      //    val.flag = 'A';
      //    val.itemId = 'N';
      //   } else {
      //    val.flag = 'X';
      //   }
      if (val.ITEM_ID != 'N' && val.ITEM_ID != null && val.ITEM_ID != '' && val.ITEM_ID != undefined) {
        // if (this.list.find(x => x.fieldName === types.stockInNo).initialValue === '' || this.list.find(x => x.fieldName === types.stockInNo).initialValue === null) {
        //  val.flag = 'A';
        //  val.itemId = 'N';
        val.flag = 'X';
      } else {
        val.flag = 'A';
        val.ITEM_ID = 'N';
        //  val.flag = 'X';
      }
      if (val.unitCode) {
        val.UNIT = val.unitCode;
      }
      this.dataSource[val.$index_edit] = val;
      this.dataSource = [...this.dataSource];
      this.EditFahuodan = false; // 编辑发货单
      this.$notify({
        title: '提示',
        message: '编辑成功',
        type: 'success'
      });
    },
    // 编辑采购  确定方法
    confirmEditCaigou(val) {
      // 旧 if (this.list.find(x => x.fieldName === types.stockInNo).initialValue === '' || this.list.find(x => x.fieldName === types.stockInNo).initialValue === null) {
      //  val.flag = 'A';
      //  val.itemId = 'N';
      // } else {
      //  val.flag = 'X';
      // }
      if (val.ITEM_ID != 'N' && val.ITEM_ID != null && val.ITEM_ID != '' && val.ITEM_ID != undefined) {
        // if (this.list.find(x => x.fieldName === types.stockInNo).initialValue === '' || this.list.find(x => x.fieldName === types.stockInNo).initialValue === null) {
        //  val.flag = 'A';
        //  val.itemId = 'N';
        val.flag = 'X';
      } else {
        val.flag = 'A';
        val.ITEM_ID = 'N';
        //  val.flag = 'X';
      }
      if (val.unitCode) {
        val.UNIT = val.unitCode;
      }
      this.dataSource[val.$index_edit] = val;
      this.dataSource = [...this.dataSource];
      this.EditCaigou = false; // 编辑采购
      this.$notify({
        title: '提示',
        message: '编辑成功',
        type: 'success'
      });
    },
    // 编辑交易平台 确定方法
    confirmEditJiaoyipingtai(val) {
      // 旧 if (this.list.find(x => x.fieldName === types.stockInNo).initialValue === '' || this.list.find(x => x.fieldName === types.stockInNo).initialValue === null) {
      //  val.flag = 'A';
      //  val.ITEM_ID = 'N';
      // } else {
      //  val.flag = 'X';
      // }
      if (val.ITEM_ID != 'N' && val.ITEM_ID != null && val.ITEM_ID != '' && val.ITEM_ID != undefined) {
        // if (this.list.find(x => x.fieldName === types.stockInNo).initialValue === '' || this.list.find(x => x.fieldName === types.stockInNo).initialValue === null) {
        //  val.flag = 'A';
        //  val.itemId = 'N';
        val.flag = 'X';
      } else {
        val.flag = 'A';
        val.ITEM_ID = 'N';
        //  val.flag = 'X';
      }
      if (val.unitCode) {
        val.UNIT = val.unitCode;
      }
      this.dataSource[val.$index_edit] = val;
      this.dataSource = [...this.dataSource];
      this.EditJiaoyipingtai = false; // 编辑交易平台
      this.$notify({
        title: '提示',
        message: '编辑成功',
        type: 'success'
      });
    },
    // 编辑文化 确定方法
    confirmEditWenhua() {},
    /** 设置页面状态 */
    async setPageState(state) {
      console.log('设置页面状态', state);
      this.pageState = state;
      if (state === pageStateTypes.none) {
        // 页面初始化
        this.shanchu = [];
        this.list.find(x => x.fieldName === types.stockInNo).disabled = false;
        this.list.find(x => x.fieldName === types.customerCode).disabled = true;
        this.list.find(x => x.fieldName == 'name').disabled = true;
        // this.list.find(x => x.fieldName === types.priceAddRate).disabled = true;
        // this.list.find(x => x.fieldName === types.tax).disabled = true;
        this.list.find(x => x.fieldName === types.stockInType).disabled = true;
        // this.list.find(x => x.fieldName === 'defaultStorage').disabled = true;
        // this.list.find(x => x.fieldName === 'areaCode').disabled = true;
        // this.list.find(x => x.fieldName === 'areaCode').initialValue = '';
        this.list.find(x => x.fieldName === types.sheetCreateDate).disabled = true;
        this.list.find(x => x.fieldName === types.remark).disabled = true;
        this.list.find(x => x.fieldName === types.settle).disabled = true;
        this.newBtnDisabled = false;
        this.saveBtnDisabled = true;
        this.bookedBtnDisabled = true;
        this.cancelBtnDisabled = true;
        this.deleteWholeList = true;
        this.showDeleteBtn = true; // 删除数据
        this.prindfBtnDisabled = true; // 打印按钮     原 true
        this.addBtnDisabled = true;
        this.returnBtnDisabled = true;
        this.fahuodanDisabled = true; // 发货单按钮
        this.caigouDisabled = true; // 采购订单按钮
        this.jiaoyipingtaiDisabled = true; // 交易平台按钮
        this.wenhuaDisabled = true; // 文化公司按钮
        this.operateBtnDisabled = null; // 操作按钮清空

        this.dcmbBtnDisabled = true; // 导出模板
        this.drBtnDisabled = true; // 导入
        this.dcBtnDisabled = true; // 导出
        this.customerName = '';
        // this.list.find(x => x.fieldName === 'wanglaikehu').initialValue = '';
        // 清数据
        this.list.find(x => x.fieldName === types.stockInNo).initialValue = '';
        this.list.find(x => x.fieldName === types.customerCode).initialValue = '';
        // this.list.find(x => x.fieldName === types.priceAddRate).initialValue = '';
        // this.list.find(x => x.fieldName === types.tax).initialValue = 0.13;
        this.list.find(x => x.fieldName === types.stockInType).initialValue = '';
        this.list.find(x => x.fieldName === types.sheetCreateDate).initialValue = '';
        this.list.find(x => x.fieldName === types.remark).initialValue = '';
        this.list.find(x => x.fieldName === types.settle).initialValue = '';
        this.list.find(x => x.fieldName == 'name').initialValue = '';
      } else if (state === pageStateTypes.new) {
        this.shanchu = [];
        // 新建状态（点击新建按钮）
        this.tax = this.cunTax;
        this.list.find(x => x.fieldName === types.stockInNo).disabled = true;
        this.list.find(x => x.fieldName === types.customerCode).disabled = false;
        this.list.find(x => x.fieldName === 'name').disabled = false;
        // this.list.find(x => x.fieldName === types.priceAddRate).disabled = true;
        // this.list.find(x => x.fieldName === types.tax).disabled = false;
        this.list.find(x => x.fieldName === types.stockInType).disabled = false;
        // this.list.find(x => x.fieldName === 'defaultStorage').disabled = false;
        // this.list.find(x => x.fieldName === 'areaCode').disabled = false;
        this.list.find(x => x.fieldName === types.sheetCreateDate).disabled = true;
        this.list.find(x => x.fieldName === types.remark).disabled = false;
        // 放开税率
        // this.list.find(x => x.fieldName === types.tax).disabled = false;
        // this.list.find(x => x.fieldName === types.tax).initialValue = this.tax ? this.tax : 0.13;
        this.newBtnDisabled = true;
        this.saveBtnDisabled = true;
        this.bookedBtnDisabled = true;
        this.cancelBtnDisabled = false;
        this.deleteWholeList = true;
        this.showDeleteBtn = true; // 删除数据
        this.prindfBtnDisabled = true;
        this.addBtnDisabled = true;
        this.returnBtnDisabled = true;
        this.dcmbBtnDisabled = true; // 导出模板
        this.drBtnDisabled = false; // 导入
        this.dcBtnDisabled = true; // 导出
        this.list.find(x => x.fieldName === types.sheetCreateDate).initialValue = moment().format('YYYY-MM-DD');
        // this.list.find(x => x.fieldName === types.tax).initialValue = this.tax;
        mutations.setTax(this.tax);
      } else if (state === pageStateTypes.add) {
        // 手工入库 状态 （选择 手工入库）
        this.list.find(x => x.fieldName === types.settle).disabled = true;
        this.addBtnDisabled = false; // 新增按钮
        this.returnBtnDisabled = true; // 退货按钮
        this.caigouDisabled = true; // 采购订单按钮
        this.dcmbBtnDisabled = false; // 导出模板
        this.fahuodanDisabled = true; // 发货单按钮
        this.jiaoyipingtaiDisabled = true; // 交易平台按钮
        this.list.find(x => x.fieldName == types.customerCode).initialValue = '';
        this.list.find(x => x.fieldName == 'name').initialValue = '';
        this.wenhuaDisabled = true; // 文化公司按钮
        this.columns.find(x => x.dataIndex == 'IN_PRICE_TAXED').disabled = false;
        this.dataSource = []; // 改变类型之后表格清空
      } else if (state === pageStateTypes.return) {
        // 采购退货 状态 （选择 采购退货）
        this.list.find(x => x.fieldName === types.settle).disabled = true;
        this.returnBtnDisabled = false; // 退货按钮
        this.addBtnDisabled = true; // 新增按钮
        this.caigouDisabled = true; // 采购订单按钮
        this.fahuodanDisabled = true; // 发货单按钮
        this.jiaoyipingtaiDisabled = true; // 交易平台按钮
        this.wenhuaDisabled = true; // 文化公司按钮
        this.dataSource = []; // 改变类型之后表格清空
      } else if (state === pageStateTypes.add_edit) {
        // 编辑状态 手工入库
        this.list.find(x => x.fieldName === types.settle).disabled = true;
        this.list.find(x => x.fieldName === types.stockInNo).disabled = true;
        this.list.find(x => x.fieldName === types.customerCode).disabled = true;
        this.list.find(x => x.fieldName === 'name').disabled = true;
        // this.list.find(x => x.fieldName === types.priceAddRate).disabled = true;
        // this.list.find(x => x.fieldName === types.tax).disabled = true;
        this.list.find(x => x.fieldName === types.stockInType).disabled = true;
        // this.list.find(x => x.fieldName === 'defaultStorage').disabled = true;
        // this.list.find(x => x.fieldName === 'areaCode').disabled = true;
        this.list.find(x => x.fieldName === types.sheetCreateDate).disabled = true;
        this.list.find(x => x.fieldName === types.remark).disabled = false;
        this.newBtnDisabled = true;
        this.saveBtnDisabled = false;
        this.bookedBtnDisabled = true;
        this.cancelBtnDisabled = false;
        this.dcmbBtnDisabled = false; // 导出模板
        this.deleteWholeList = false;
        this.showDeleteBtn = true; // 删除数据
        this.prindfBtnDisabled = true;
        this.addBtnDisabled = true;
        this.returnBtnDisabled = true;
        this.dataSource = []; // 改变类型之后表格清空
      } else if (state === pageStateTypes.return_edit) {
        // 编辑状态 采购退货 (和入库一样)
        this.list.find(x => x.fieldName === types.settle).disabled = true;
        this.list.find(x => x.fieldName === types.stockInNo).disabled = true;
        this.list.find(x => x.fieldName === types.customerCode).disabled = true;
        this.list.find(x => x.fieldName === 'name').disabled = true;
        // this.list.find(x => x.fieldName === types.priceAddRate).disabled = true;
        // this.list.find(x => x.fieldName === types.tax).disabled = true;
        this.list.find(x => x.fieldName === types.stockInType).disabled = true;
        // this.list.find(x => x.fieldName === 'defaultStorage').disabled = true;
        // this.list.find(x => x.fieldName === 'areaCode').disabled = true;
        this.list.find(x => x.fieldName === types.sheetCreateDate).disabled = true;
        this.list.find(x => x.fieldName === types.remark).disabled = false;
        this.newBtnDisabled = true;
        this.saveBtnDisabled = false;
        this.bookedBtnDisabled = true;
        this.cancelBtnDisabled = false;
        this.deleteWholeList = false;
        this.showDeleteBtn = false; // 删除数据
        this.prindfBtnDisabled = true;
        this.addBtnDisabled = true;
        this.returnBtnDisabled = true;
        this.dataSource = []; // 改变类型之后表格清空
      } else if (state === pageStateTypes.fahuodan) {
        // 发货单 状态 （选择 发货单）
        this.list.find(x => x.fieldName === types.settle).disabled = false;
        this.fahuodanDisabled = false; // 发货单按钮
        this.addBtnDisabled = true; // 新增按钮
        this.returnBtnDisabled = true; // 退货按钮
        this.caigouDisabled = true; // 采购订单按钮
        this.jiaoyipingtaiDisabled = true; // 交易平台按钮
        this.dcmbBtnDisabled = true; // 导出模板
        let appId = await getAppId();
        if (appId == 'arcfox') {
          this.list.find(x => x.fieldName == types.customerCode).initialValue = 'arcfox';
          this.list.find(x => x.fieldName == 'name').initialValue = '北京蓝谷极狐汽车科技有限公司';
        } else {
          this.list.find(x => x.fieldName == types.customerCode).initialValue = '';
          this.list.find(x => x.fieldName == 'name').initialValue = '';
        }
        this.columns.find(x => x.dataIndex == 'IN_PRICE_TAXED').disabled = true;
        this.wenhuaDisabled = true; // 文化公司按钮
        this.dataSource = []; // 改变类型之后表格清空
      } else if (state === pageStateTypes.caigou) {
        // 采购订单 状态 （选择 采购订单）
        this.list.find(x => x.fieldName === types.settle).disabled = false;
        this.caigouDisabled = false; // 采购订单按钮
        this.fahuodanDisabled = true; // 发货单按钮
        this.addBtnDisabled = true; // 新增按钮
        this.returnBtnDisabled = true; // 退货按钮
        this.jiaoyipingtaiDisabled = true; // 交易平台按钮
        this.wenhuaDisabled = true; // 文化公司按钮
        this.dataSource = []; // 改变类型之后表格清空
      } else if (state === pageStateTypes.jiaoyipingtai) {
        // 交易平台 状态 （选择 交易平台）
        this.list.find(x => x.fieldName === types.settle).disabled = false;
        this.jiaoyipingtaiDisabled = false; // 交易平台按钮
        this.caigouDisabled = true; // 采购订单按钮
        this.fahuodanDisabled = true; // 发货单按钮
        this.addBtnDisabled = true; // 新增按钮
        this.returnBtnDisabled = true; // 退货按钮
        this.wenhuaDisabled = true; // 文化公司按钮
        this.dataSource = []; // 改变类型之后表格清空
      } else if (state === pageStateTypes.wenhua) {
        // 文化公司 状态 （选择 文化公司）
        this.list.find(x => x.fieldName === types.settle).disabled = false;
        this.wenhuaDisabled = false; // 文化公司按钮
        this.jiaoyipingtaiDisabled = true; // 交易平台按钮
        this.caigouDisabled = true; // 采购订单按钮
        this.fahuodanDisabled = true; // 发货单按钮
        this.addBtnDisabled = true; // 新增按钮
        this.returnBtnDisabled = true; // 退货按钮
        this.dataSource = []; // 改变类型之后表格清空
      } else if (state === pageStateTypes.kucun) {
        console.log('库存导入');
        // 库存导入 状态 （选择 库存导入)
        this.list.find(x => x.fieldName === types.settle).disabled = true;
        this.list.find(x => x.fieldName === types.tax).disabled = true;
        this.dcmbBtnDisabled = false; // 导出模板
        this.drBtnDisabled = false; // 导入
        this.addBtnDisabled = true; // 新增按钮
        this.wenhuaDisabled = true; // 文化公司按钮
        this.jiaoyipingtaiDisabled = true; // 交易平台按钮
        this.caigouDisabled = true; // 采购订单按钮
        this.fahuodanDisabled = true; // 发货单按钮
        this.addBtnDisabled = true; // 新增按钮
        this.returnBtnDisabled = true; // 退货按钮
        this.dataSource = []; // 改变类型之后表格清空
        // this.columns.find(x => x.dataIndex == 'IN_PRICE_TAXED').disabled = true;
      }
      this.list = [...this.list];
    },
    async initDictData() {
      // 仓库
      this.quertStorageListByIncountType();
      // 品牌
      mutations.setDict_pp([]);
      // 配件类别
      mutations.setDict_pjlb(this.createDictList(8075));
    },
    // 根据入库类型查询仓库列表(oem/非oem)
    async quertStorageListByIncountType(value) {
      // 只有手工入库的能够编辑价格
      this.hideoperation = !!!(value == 80881001);
      // 退货类型的订单入库数量不能大于0
      this.columns.find(item => item.dataIndex == 'IN_QUANTITY').min = value == 80881002 ? -Infinity : 0;
      this.columns.find(item => item.dataIndex == 'IN_QUANTITY').max = value == 80881002 ? 0 : Infinity;

      let oemStorageType = ['80881003', '80881005'], // 发货单 交易平台 oem
        // noOemStorageType = ['80881001', '80881004']; // 手工，采购订单 非oem
        noOemStorageType = ['80881004']; // 采购订单 非oem  EP-23605 去除入库oem类型限制
      let oemTag = '';
      if (oemStorageType.includes(value + '')) {
        oemTag = 1;
      } else if (noOemStorageType.includes(value + '')) {
        oemTag = 0;
      }
      // 增加模块区分
      const ckRes = await getStorageList({
        type: oemTag
        // ptype: 'SPA'
      });
      const ckDict = ckRes.data.map(x => ({ text: x['STORAGE_NAME'], value: x['STORAGE_CODE'] }));
      this.ckDataList = ckRes.data;
      this.columns.find(x => x.dataIndex === 'STORAGE_CODE').editItems = ckDict;
      this.columns.find(x => x.dataIndex === 'STORAGE_CODE').filterItems = ckDict;
      // this.list.find(item => item.fieldName == 'defaultStorage').itemList = ckDict;
      // this.list.find(item => item.fieldName == 'defaultStorage').initialValue = ckDict.length ? ckDict[0].value : '';
      this.storageDic = ckDict;
      mutations.setDict_ck(ckDict);
    },
    // 点击行项选择库位
    async handleChosePosition(row) {
      let rowStorageCode = row.STORAGE_CODE;
      // 判断该配件在该仓库中是否存在可用库位
      let checkResult = await queryParyHasStorageById({
        storageCode: rowStorageCode,
        partNo: row.PART_NO
      });
      if (checkResult.data.length && checkResult.data[0].storagePositionCode) {
        Util.notifyAction('该配件在此仓库中存在可用库位不能修改库位', 'warning');
        let positionCode = checkResult.data[0].storagePositionCode;
        // 如果库位篮子中有此库位将此库位移除并且赋值给行项
        this.storagePositionList[rowStorageCode] &&
          this.storagePositionList[rowStorageCode].includes(positionCode) &&
          this.storagePositionList[rowStorageCode].splice(this.storagePositionList[rowStorageCode].indexOf(positionCode), 1);
        this.dataSource[row.$index].STORAGE_POSITION_CODE = positionCode;
        return;
      }
      // 判断该配件是否存在已选择库位的相同配件
      let listSamePartInfo = this.dataSource.find(item => item.PART_NO == row.PART_NO && (item.STORAGE_POSITION_CODE || item.STORAGE_POSITION_CODE == 0)); // 配件号相同并且有库位的配件
      if ((listSamePartInfo && listSamePartInfo.STORAGE_POSITION_CODE) || listSamePartInfo.STORAGE_POSITION_CODE === 0) {
        Util.notifyAction('列表中存在相同配件，已自动赋值库位', 'warning');
        this.dataSource[row.$index].STORAGE_POSITION_CODE = listSamePartInfo.STORAGE_POSITION_CODE;
        return;
      }

      // console.log(row);
      // 修改库位时判断库位篮子里是否有该仓库的库位没有则查询并添加
      let rowSortagePosition = this.storagePositionList[rowStorageCode];
      if (!rowSortagePosition) {
        let res = await queryUseablePositionListByStorage({
          storageCode: rowStorageCode
          // areaCode: this.list.find(item => item.fieldName == 'areaCode').initialValue || ''
        });
        if (res.resultCode == 200) {
          if (res.data[0].error) {
            Util.notifyAction(res.data[0].error, 'warning');
          } else {
            this.storagePositionList[rowStorageCode] = res.data.map(item => item.storagePositionCode);
            this.handleChosePosition(row);
          }
        }
      } else {
        rowSortagePosition.includes(row.STORAGE_POSITION_CODE) && rowSortagePosition.splice(rowSortagePosition.indexOf(row.STORAGE_POSITION_CODE), 1);
        this.positionDialogList = rowSortagePosition;
        this.positionEditRow = row;
        this.positionListVisible = true;
      }
    },
    // 选择库位点击确定
    handlePositionSelectConfirm(e) {
      // console.log(e, this.storagePositionList);
      // 库位篮子中存在此库位将其移除
      try {
        this.storagePositionList[e.srotage] &&
          this.storagePositionList[e.srotage].includes(e.code) &&
          this.storagePositionList[e.srotage].splice(this.storagePositionList[e.srotage].indexOf(e.code), 1);
      } catch (err) {
        console.log(err);
      }
      e.oldCode && this.storagePositionList[e.srotage].unshift(e.oldCode); // 如果有旧库位则将旧库位插入到现有库位的最前方

      this.dataSource[e.index].STORAGE_POSITION_CODE = e.code;
    },
    // 计算table中数据（含税价格等）
    computedTableData(newVal) {
      let tax = this.tax;
      newVal.map(item => {
        let inCount = item.IN_QUANTITY ? +item.IN_QUANTITY : 0;
        // item.IN_PRICE_TAXED = item.IN_PRICE_TAXED || item.IN_PRICE * (1 + tax * 1);
        // item.IN_PRICE = item.IN_PRICE_TAXED / (1 + tax * 1);
        if (!item.isflg) {
          // item.IN_PRICE_TAXED = (item.IN_PRICE || 0) * (1 + tax * 1);
          item.IN_PRICE = (item.IN_PRICE_TAXED || 0) / (1 + tax * 1);
        }
        item.IN_AMOUNT = (item.IN_PRICE * inCount).toFixed(2);
        item.IN_AMOUNT_TAXED = ((item.IN_PRICE_TAXED || 0) * inCount).toFixed(2);
      });
    },
    // 设置业务往来客户默认为一汽大众
    setDefaultDealerToVw() {
      this.list.find(x => x.fieldName === types.customerCode).initialValue = this.defaultDealerCodeName.code;
      this.customerName = this.defaultDealerCodeName.name;
      // this.list.find(x => x.fieldName === 'wanglaikehu').initialValue = this.defaultDealerCodeName.name;
    },
    // 设置table可编辑字段编辑状态
    setTableEditStatus(val) {
      let fieldList = ['IN_QUANTITY', 'V_INVOICE_NO'];
      fieldList.map(item => {
        this.columns.find(item2 => item2.dataIndex == item).editable = val;
        this.columns.find(item2 => item2.dataIndex == item).defaultEditable = val;
      });
    },
    // 点击默认空库位(递归赋值操作)
    handleAssignLeisurePosition() {
      if (!this.dataSource.length) {
        Util.notifyAction('请先添加配件明细', 'warning');
        return;
      }
      if (this.assignLeisureLoading) return;
      this.assignLeisureLoading = true;
      this.recursionAssignLeisurePosition(0);
    },
    // 递归赋值空闲库位
    async recursionAssignLeisurePosition(index) {
      if (index > this.dataSource.length - 1) {
        this.assignLeisureLoading = false;
        Util.notifyAction('空闲库位赋值成功,若没有库位则此仓库或库区下没有可用库位', 'success');
      } else {
        let rowData = this.dataSource[index];
        if (rowData.STORAGE_CODE && rowData.STORAGE_POSITION_CODE !== 0 && !rowData.STORAGE_POSITION_CODE) {
          let listSamePartInfo = this.dataSource.find(item => item.PART_NO == rowData.PART_NO && (item.STORAGE_POSITION_CODE || item.STORAGE_POSITION_CODE == 0)); // 配件号相同并且有库位的配件
          if (listSamePartInfo && (listSamePartInfo.STORAGE_POSITION_CODE || listSamePartInfo.STORAGE_POSITION_CODE === 0)) {
            // 列表中已经有该配件并且已经赋值库位的情况下直接取已有库位
            this.dataSource[index].STORAGE_POSITION_CODE = listSamePartInfo.STORAGE_POSITION_CODE;
            this.recursionAssignLeisurePosition(index + 1);
          } else if (this.storagePositionList[rowData.STORAGE_CODE] && this.storagePositionList[rowData.STORAGE_CODE].length) {
            // 当库位篮子中有此仓库的值并且此仓库可用库位列表不为空的时候取第一个空库位 赋值给当前行
            if (this.storagePositionList[rowData.STORAGE_CODE][0] || this.storagePositionList[rowData.STORAGE_CODE][0] === 0) {
              this.dataSource[index].STORAGE_POSITION_CODE = this.storagePositionList[rowData.STORAGE_CODE][0];
              this.storagePositionList[rowData.STORAGE_CODE].splice(0, 1);
            }
            this.recursionAssignLeisurePosition(index + 1);
          } else {
            let storagePositionCodes = this.dataSource.map(x => {
              if (x.STORAGE_CODE == rowData.STORAGE_CODE) {
                return x.STORAGE_POSITION_CODE;
              }
            });
            // 库位篮子中没有此库位的时候请求库位数据并添加到篮子中
            let res = await queryUseablePositionListByStorage({
              partNo: rowData.PART_NO,
              storageCode: rowData.STORAGE_CODE,
              storagePositionCodes: storagePositionCodes
              // areaCode: this.list.find(item => item.fieldName == 'areaCode').initialValue || ''
            });
            if (res.resultCode == 200 && !res.data[0].error) {
              this.storagePositionList[rowData.STORAGE_CODE] = res.data.map(item => item.storagePositionCode);
              this.recursionAssignLeisurePosition(index);
            } else {
              this.recursionAssignLeisurePosition(index + 1);
            }
          }
        } else {
          this.recursionAssignLeisurePosition(index + 1);
        }
      }
    },
    async qianliaotest() {
      let hansIndebtpartRes = await queryInventoryPartIsRelevanceInDebt({
        stockInNo: this.getFormListValue(types.stockInNo)
      });
      console.log(hansIndebtpartRes);
      if (hansIndebtpartRes.resultCode == 200 && hansIndebtpartRes.data.rows.length) {
        this.inDebtstockInNo = this.getFormListValue(types.stockInNo);
        this.inDebtVisible = true;
      }
    },
    // 默认库区变化修改仓库篮子中的库位数据
    async handleAreaCodeChange(val) {
      // let storageCode = this.list.find(item => item.fieldName == 'defaultStorage').initialValue;
      if (storageCode) {
        let res = await queryUseablePositionListByStorage({
          storageCode,
          areaCode: val
        });
        if (res.resultCode == 200) {
          if (!res.data.length) {
            notifyAction('新库区中无可用库位，可能导致无法选择库位，请重新输入', 'warning');
          }
          this.storagePositionList[storageCode] = res.data.map(item => item.storagePositionCode);
        }
      }
    },
    // 查询打印参数
    async queryPrintParams() {
      let res = await dealerPrintApi({
        vModule: '90211009',
        vNormalCode: 'BJRK'
      });
      if (res.resultCode == 200 && res.data.length) {
        this.printParams = res.data[0];
      }
      console.log(this.printParams, '打印参数');
    },
    // 签收关闭事件
    handleSignDialogClose() {
      this.signVisible = false;
      this.cancelBtnClick();
    }
  }
};
</script>

<style scoped lang="less">
.btn-group {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 60px;
}
</style>
